Cash Register lesson in Codecademy

While completing the Cash Register (step 3/7) exercise on Codecademy’s JavaScript course, I came across this answer from tony de araujo that helped me understand how the code I was writing was executed.

alt text

On line 29 we call the scan method from object cashRegister and pass in an item called “eggs”

“eggs” gets inserted into the function via the input parameter item which is an interface.

For this function call instance, “eggs” becomes the value of variable item.

The switch switches the case “eggs” to true, which triggers the function add on line 4 and the value of 0.98 is added to variable total on line 2.

In truth, the program only starts executing at line 29. All the stuff above line 29 is preliminary data that JavaScript will use once it starts running the program. What I mean is that JavaScript scans the program once and it makes an inventory of what is supposed to do. Then, it starts running at line 29 and downward.


Leave a Reply

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

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

Google photo

You are commenting using your Google 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