This lab will further help you understand how functions and blocks determine scope in JavaScript.
The Flatburger restaurant is beginning to create its menu of food and drinks to sell to its customers. You will need to use your knowledge of scope to access and change some of these variables.
It is recommended that you use the Visual Studio Code (VSCode) IDE for this lab.
Useful considerations and terminology:
Scope: The concept of where something is available.
Globally-scoped variable: A variable that is globally accessible and can be accessed from anywhere in the JavaScript script.
Function-scoped variable: A variable that can only be accessed inside of a function.
Block-scoped variable: A variable that can only be accessed inside of a block.
Here are some other useful resources:
In this lab, you will practice declaring variables in global scope, creating variables that are function-scoped, and creating variables that are block-scoped.
Fork and clone this lab into your local environment. Navigate into its
directory in the terminal, then run code . to open the files in Visual Studio
Code.
These are your tasks:
burgers: Declare a variable in global scope calledburgersusing theconstkeyword and assign it the value of an array that has the following 2 elements:'Hamburger'and'Cheeseburger'.featuredDrink: Declare a variable in global scope calledfeaturedDrinkusing theletkeyword and assign it the value'Strawberry Milkshake'.addBurger(): Write a function namedaddBurgerthat when called, does the following in this exact order:- Creates a function-scoped variable named
newBurgerusing theconstkeyword and assigns it the value'Flatburger'. - Uses the
.push()array method to addnewBurgerto theburgersarray.
- Creates a function-scoped variable named
if(true): Write anifstatement whose condition istrue, so that the code in its block will always execute. The code inside of theifstatement’s block should do the following in this exact order:- Create a block-scoped variable named
anotherNewBurgerusing theconstkeyword and assign it the value'Maple Bacon Burger'. - Use the
.push()array method to addanotherNewBurgerto theburgersarray.
- Create a block-scoped variable named
changeFeaturedDrink(): Write a function namedchangeFeaturedDrinkthat when called, changes the value of thefeaturedDrinkvariable to'The JavaShake'.
When you're done with this lab, remember to commit and push your changes up to GitHub, then submit your work to Canvas using CodeGrade.