3. JavaScript Basics Syntax
Syntax: Spelling and grammar rules of a
programming language
Like any language, there are formal rules
around how to write it. This is syntax.
5. Code Along
Start with a folder and a template
● desktop folder (07_js_basics)
● css folder > normalize.css, style.css
● js folder
● template.html
6. Variables
●
●
●
We can tell our program to remember values
for us to use later on.
The action of saving a value to memory is
called assignment.
The entity we use to store the value is called
a variable.
7. Variables
●
●
The action of getting the value from a
variable is called accessing the variable.
We will use the above techniques to store
values into variables, and generate new
values using existing variables.
16. Assignment
Google “New England Patriots” or “Boston Celtics”
Use JavaScript to capture box score information
and then display that information.
● team names (two variables)
● points scored in each quarter (eight variables)
18. Conditionals
“condition” must be “true” for that code block to
execute.
if (today is Wednesday) {
document.write(“Just two more work days”);
}
Google: “javascript string to lowercase”
19. Conditionals
Add an “else” condition:
if (today is Wednesday) {
document.write(“Just two more work days”);
} else {
document.write (“Keep working.”)
}
20. Conditionals
if (today is Wednesday) {
document.write(“Just two more work days.”);
} else if (today is Thursday) {
document.write(“Just one more work day.”)
} else {
document.write(“Just keep working.”)
}
22. Lab
Build a simple page that prompts the visitor for
size of pizza and number of toppings; then
display the correct price.
Bonus: Prompt for name and actual toppings
and display as well.
Bonus: Build sales tax of 6.25% into price.