My Virtual Pet Worksheet
Pet owner's name: ____________________
Pet's name: ____________________
Pet type: ____________________
Pet's age: ____________________
Pet's weight: ____________________
Pet's hunger: ____________________
Pet's health: ____________________
Pet's happiness: ____________________
What is a virtual pet?
____________________________________________________________________________
What is a variable?
____________________________________________________________________________
What is JavaScript?
____________________________________________________________________________
My First JavaScript Program
1 // This is a comment. Comments help to explain what the code does.
2 // The following is an example of a variable.
3 // The name (or label) of the variable is petOwnerName.
4 // The value (or data) stored in petOwnerName is the string
5 // "John Doe".
4 var petOwnerName = "John Doe";
5 // The following instruction creates a pop up box.
6 // The pop up box tells you the name of the pet owner.
7 alert("The pet owner's name is " + petOwnerName);
Common Syntax Errors
Incorrect capitalization: Var x = 10;
Correct capitalization: var x = 10;
Var and var are not the same. The keyword var in JS must be in lower case only.
Adding a space between the function name and the parentheses.
Incorrect: myFunction (x, y);
Correct: myFunction(x, y);
Forgetting to end a statement with a semicolon;
Incorrect: x = x + 4
Correct: x = x + 4;
Commenti