Objectives

Asynchronous JS

Identify JavaScript as a language that utilizes an event loop model

Identify JavaScript as a single threaded language

Describe the difference between asynchronous and synchronous code

Execute the asynchronous function setTimeout with a callback.

function foo(food1, food2) {
  console.log(food1 + " for breakfast");
  console.log(food2 + " for lunch");
}

setTimeout(foo, 2000, "pancakes", "couscous");

Given the function predict the output of “asyncy(callback);”

"function asyncy(cb) { setTimeout(cb, 1000); console.log("async") }"
"function callback() { console.log("callback"); }",

Use setInterval to have a function execute 10 times with a 1 second period. After the 10th cycle, clear the interval.

setInterval(function () {
  console.log("hello");
}, 5000);

Write a program that accepts user input using Node’s readline module

const askGuess = () => {
  rl.question(
    "Berber asks: Can you guess how many snacks I want to eat right now? ",
    (answer) => {
      !checkGuess(Number(answer)) ? askGuess() : rl.close();
    }
  );
};