Introduction to JavaScript and Web Design
1. In this code, several variables are used to store and work with numbers. The variable price1 stores the value 5, and price2 stores the value 6. These two values are added together, and the result is stored in the variable total. Variables make it easier to store information and reuse it later in the program. The code also uses the document object, which is a built-in JavaScript object that represents the web page itself. Using document.getElementById("demo"), the code is able to find the paragraph element with the id demo and update its content. Overall, the code works by adding price1 and price2 together and saving the result in total. Then, the document object inserts the text “The total is: 11” into the paragraph on the webpage so the result is displayed to the user. 2. In Chapters 2–4 of Eloquent JavaScript, I learned about program structure, variables, expressions, functions, and how control flow work...