Lesson #3 Review Questions

Back to Lesson # 3 Variables and Values Table of Contents # 3 Assignment

 

1. Variables used in a program are most like ...

Looking up a word in a dictionary
The stock market, since it varies by going up and down.
A mailbox, which holds information for later use. JavaScript 1.1
Information carved in stone, to be stored forever. JavaScript 1.2
2. Which of the following is NOT a valid name for a variable in JavaScript?

alert
myAlertMessage
studentGrade
i
3.Which of the following is NOT a rule for naming variables?

No JavaScript keywords may be used.
No four letter words can be used for variable names.
No spaces are allowed in variable names.
The underscore character _ may be used for better readability.

4. Which of the following is NOT a 'type' of data in JavaScript?

string
negative numbers
float
boolean
5. Besides valid and invalid variable names, we like to have the variable names be helpful and descriptive. Not too short and not too long. Which of the following would be valid but unwise to use as a variable name.

userName
tirePressure
totalPrice
number
6.The use of the dollar sign $ should be avoided in variable names since some older browser versions won't accept it.

True
False
7. When we use the prompt() method to store data in a variable, it is always stored as what data type?

int
string
float
boolean

8.The keyword 'var' should be used

every time you use a variable name in a JavaScript statement.
at the top of the function code.
when you first create a variable and give it a name.
at the start of every JavaScript assignment statement.

9. Suppose you are writing a program to calculate the number of calories in the pizza you ate for lunch. You use the prompt() method to ask the user for the number of slices they had. Then multiply the number of slices by 350 calories, and output the answer. In order to do the math, you need to convert the number of slices to a float data type. Which method do you need to use?
parseInt()
parseFloat()
Math.convert()

convertFloat()

10. Variables get their data type from the values that are stored in them, and can change type as the program executes..

True
False

Return to Top of Page | Back to Main Menu