Order Drink Callback Function

For this coding challenge, I had to write a callback function that ordered a beverage at a cafe. I am currently in the processes of learning Javascript in both my MIT/Emeritus Coding Bootcamp and my Codecademy Full Stack course. This challenge helped me better understand callback functions and how they work. You can check out my orderDrink callback function on my GitHub.

I also wrote a callback function that sent directions in steps to my friends house every 1 second using setInterval. This used an anonymous function to iterate through an array and provide the step-by-step instructions. This was a simpler function but I struggled with making it work. I always make my code unnecessarily complicated so Rich helped me simplify it.

const directions = [‘Take a left on South St.’, ‘Go North for 1.5 miles’, ‘Slight right on Bernard Rd.’, ‘Right on Harper St.’, ‘Its the second house on the left’]

var i = 0;

setInterval(function(){

if(i < directions.length){

console.log(directions[i])

i++

};

}, 1000)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: