Lesson #6 Review Questions

Back to Lesson # 6 - Data Types and Operators Table of Contents # 6 Assignment

 

 

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

int
decimal
boolean
string
2. For strings, the + sign does what?

addition, just as for numbers
converts to upper case
concatenates
just acts as any other punctuation mark

3. What is the value of var someString after the following statements?

	var someString="Hasta La Vista";
	someString +="Baby"; 
HASTA LA VISTA
Hasta La VistaBaby
Hasta La Vista
Baby Hasta La Vista
4. How could the indexOf() method be helpful in checking to see if a person's email address was valid? Hint: email addresses must contain the @ symbol somewhere.

indexOf() is the wrong method, you should be using the length() method to check an email address
If indexOf("@") returns a 0, then you know you have a bogus or invalid email address.
If the indexOf("@") method returns a -1 then you would know there was not an @ in the address, so it could not be valid.
If the indexOf("@") method returns a value such as 7, then you would know for sure that the email address could not be valid.

5. What is the output?

	var userPassword = "Guest";
	var count = userPassword.length();
	alert( count ); 
4
6
1
5

6. What is the output?

	var myCar="Corvette 1953 ";
	alert( myCar.substring(9,4) ); 
Corvette
1953
ette
rvette 19

7. Since both text boxes and the prompt() method store data as strings, how could we convert the string "1953" to a number?

int()
convertDigits()
parseInt()
parseWholeNumber()
8. How could you use parseInt() to display your instructor's age in binary?
age = parseBinary( age, 2);
age = age.parseBinary();
age = age % 2;
age = parseInt(age, 2);
9. What is the value of 17 % 5?

3
12
0.8
2
10. What is the formula for simulating a random number from 1 to 6 as in a dice game?
dice1= Math.random() * 6;
dice1= Math.floor(Math.random() * 6) +1;
dice1 = Math.random(Math.floor() * 6 + 1);
dice1 = Math.round(Math.random() * 6);

Return to Top of Page | Back to Main Menu