Programming Primer (in JS)
This is an exercise to practice basic programming principles.
Instructions
The code of this exercise can be executed via Node.js or in the console tab of your browser's developer tools.
Define an
addFavoriteBook(..)function that receives a single parameter, calledbookName.If the provided
bookNamestring does NOT have the word "Great" in it, add it to thefavoriteBooksarray.Hints:
someString.includes(anotherString)will returntrueifanotherStringis found insidesomeString, orfalseotherwise.Use
!to negate a boolean value (changetruetofalseor vice versa).someArray.push(value)will add a value to the end of the array.
Define a
printFavoriteBooks()function that receives no parameters.printFavoriteBooks()should first print a message like "Favorite Books: ..", and include the number of books in thefavoriteBooksarray.Hint:
Use the ` back-tick operators for strings that need to include values in them.
Use
console.log(..)to print a message to the screen.
Finally,
printFavoriteBooks()should loop through thefavoriteBooksarray and print out each value.Make sure to then call the
printFavoriteBooks()function at the end of the program.Hint: Use the
for ( let .. of .. ) { }style loop.