This section contains a few questions for you to answer to make sure you understand the concepts from the previous chapter.
Before proceeding with the exercises, create a new branch in git
git checkout -b JS1
where JS1 is the new branch nameFor the first 4 exercises, write a line of code that uses each function. Note that not all these functions exist, so you don’t need to try running them on your computer. Here's an example:
Example
Run the includes
function, which takes in 1 argument, a string.
Exercises
Run the map
function, which takes in 1 argument, a function.
Run the setTimeout
function, which takes in 2 arguments, a function and a number.
Run the app.get
function, which takes in 2 arguments, a string and a function.
Run the fs.writeFile
function, which takes in 3 arguments: a string, a string, and a function.
Solve the following:
const lannister = (input) => {
return input
}
const stark = () => {
return 99
}
let res = stark // what is res?
res = lannister( stark ) // what is res?
res = lannister( stark() ) // what is res?
Solve the following:
const baratheon = (run_me) => {
return run_me() + 5
}
const tyrell = () => {
return 10
}
let res = tyrell // what is res?
res = baratheon( tyrell ) // what is res?
res = baratheon( () => {
return 92
}, 3) // what is res?
res = baratheon( () => {
const b = 95
tyrell()
}) // what is res?
How did you do? If you had any issues solving any of the Preflight questions, please review the previous lesson by doing all the exercises and challenges again. When you're confident you have a strong foundation, let's move on!
<aside> 💡 In case you feel frustrated because it seems like we are deliberately putting in trick questions... Truth is, we are. The reason why we made the exercises so tricky that you have to step through it line by line is because when you work as an engineer, you will frequently come across bugs / other people's code that will force you to go through code line by line. This skill is a big part of engineering and many students are not prepared for this if they only focus on learning.
</aside>