Lesson #7 Review Questions

Back to Lesson # 7 - Branching and Decisions Table of Contents # 7 Assignment

 

 

1. What is wrong with this?

 if ( age = 16 )

	alert("16 is legal driving age.");
age is not a valid variable name
the = sign should be == to test two values for equality
there should be a semicolon ; after the 'if' statement
nothing is wrong
2. If 'var breed = "Pitbull', then will (breed == "pitbull") be true or false?

cannot tell from this information
true
false

3. In a certain high school, students with a 3.5 gpa have the message "Graduate with Honors" on their academic record. What is the best structure to handle this in a program?

if ( gpa >= 3.5) ...
if ( gpa >= 3.5) ...else ...
switch gpa { ...}
<option> tags
4. Students of this school who are in grade 11 or above are eligeable to apply for a campus parking permit, but otherwise they get a district bus pass. Which is the best structure for this situation
if ( grade >= 11 ) {...}
if ( grade >= 11 ) then {...} else {...}
switch grade { ...}
<option> tags

5. Students are asked to mark radio buttons to indicate the sport that they participate in for fall season,( football, soccer, cross country, or none) and receive the correct messages from the athletic department.

if ( sport == "soccer") ...
if ( sport == "soccer") {...} else { ...}
<options> tags
switch sport { ...}

6. In the cartoon quiz, what structure is used to score each quiz question

one if...then statement
a series of if statements
a series of if...else... statements
a switch construct based on 'response' as the variable

7. Since there are 4 possible choices to each question, which construct would be the best one to use here?

one if...then statement
a series of if statements
a series of if...else... statements
a switch construct based on 'response' as the variable
8. If you needed to use a lookup system in a web page to ask the user to enter the zip code of their mailing address, and have the computer come up with the name of the city, which construct would be the best to use?
if (..) ...
if ( ...) ... else...
switch
<option> tags
9. Which would be considered 'smaller' in the computer's way of comparing, 'beauty' or 'beast'?

beauty
beast
10. Suppose that you need to have 4 statements execute when a condition is true. What do we need to remember when writing the code?
We need to place the 'if (...) ' condition in front of all 4 statements
We need to enclose all 4 statements inside of {...} braces so that they execute as a block of code
We need to enclose all of the 4 statements inside of a function definition.
We need to use parentheses to control the order of operations.

Return to Top of Page | Back to Main Menu