From 12e27eaf0105c6b46ee7c861083bb04234917a6d Mon Sep 17 00:00:00 2001 From: Mia yun Ruse Date: Tue, 12 Nov 2024 15:02:39 +0000 Subject: [PATCH] Update README.md use js formatting. link to Shortcut that I came up with for use in my own alarm --- README.md | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 377caeb..16f7d34 100644 --- a/README.md +++ b/README.md @@ -5,33 +5,25 @@ I created this fetchable api to be used by whoever needs it to provide several p ### Endpoint: https://avyrie.github.io/affirmations-api/affirmations.json ## Fetch Random Affirmation -The below code can be used to fetch a random affirmation from this api using JS fetch: +The following node.js code can fetch a random affirmation: +```js const fetch = require('node-fetch'); -
const url = 'https://avyrie.github.io/affirmations-api/affirmations.json'; -
const randomNum = (arrLength) => { -
return Math.floor(Math.random() * arrLength) -
} -
const fetchData = () => { -
fetch(url) -
.then(response => response.json()) -
.then(data => console.log(data.affirmations[(randomNum(data.affirmations.length))])) -
.catch(err => { -
console.log(err) -
}) -
} +``` + +If you are running iOS, there is a [Shortcut to fetch a random affirmation](https://www.icloud.com/shortcuts/88824df962704cb9b2ec73c7b1624895) which can be used as a building block - say in an alarm. ## Contributing