70 likes | 158 Views
REVIEW FOR LESSON 8. Boolean Logic. 1. What does the following write to the output window? var dude:Boolean = false; var score:Number = 10; if (dude == true) { trace(score+20); } else { trace(score-10); }. false 30 10 0.
E N D
REVIEW FOR LESSON 8 Boolean Logic
1. What does the following write to the output window?vardude:Boolean = false;varscore:Number = 10; if (dude == true) { trace(score+20); } else { trace(score-10);} • false • 30 • 10 • 0
2. What does the following write to the output window?varscore:Number = 10; if (score < 10) { trace(“Hello Bobby!”); } else if (score > 10) { trace(“Hello Danielle!”); } else { trace(“Hello Jill!”); } • 10 • Hello Bobby! • Hello Danielle! • Hello Jill!
3. What does the following write to the output window? var p1Score:Number = 25; var p2Score:Number = 30;varmaxScore:Number = 50;if (p1Score + p2Score >= maxScore){maxScore = p1Score + p2Score; trace(maxScore);}else{ trace("You didn’t win!! My score of " + maxScore + " is still the best!");} • Syntax Error • 50 • 55 • You didn’t win!! My score of 50 is still the best!
4. What does the following write to the output window? var p1Score:Number = 25; var p2Score:Number = 30;varmyTurn:Boolean = true;if (p1Score >= p2Score && myTurn == false){ trace(“I’m winning, but it’s your turn.”);}else if (p1Score <= p2Score && myTurn == false){ trace(“I’m losing, and it’s your turn! Aah!”);}else if (p1Score == p2Score && myTurn == false){ trace(“We’re tied, but it’s your turn.”);}else if (p1Score == p2Score && myTurn == true){ trace(“We’re tied, but it’s my turn.”);}else if (p1Score >= p2Score && myTurn == true){ trace(“I’m winning, and it’s my turn.”);}else if (p1Score <= p2Score && myTurn == true){ trace(“I’m losing, but it’s my turn! Ha!”);} • I’m winning, but it’s your turn. • I’m losing, but it’s my turn! Ha! • I’m winning, and it’s my turn. • Nothing
5. What does the following write to the output window? varhasLicense:Boolean = false;varhasCar:Boolean = true;varmyAge:Number = 16;varsheWantsToGo:Boolean = true;if (hasLicense == true && sheWantsToGo == true){ trace("Let’s go!");}if (myAge >=16 && hasCar == true){ trace("I’ll go.");}if (hasLicense == false && hasCar == false || sheWantsToGo == true){ trace("I’ll find a way to go…");}if (hasCar == true && sheWantsToGo == true && hasLicense == false){ trace("We’re going anyway")}else { trace("I’m a loner… but that’s okay.");} • I’ll go. • I’ll find a way to go… • We’re going anyway • I’ll go. I’ll find a way to go… We’re going anyway
6. If statements can use shorthand comparisons to check whether a statement is true, for example:if(HaveFriends == true) is the same thing as if(HaveFriends)Placing the ‘== true’ is unnecessary. It also works for false statements, for example:if(HaveFriends != true) is the same thing as if(!HaveFriends) Knowing this, what does the following write to the output window? varallMyFriendsDoIt:Boolean = true;varitsJustOne:Boolean =true;varnobodyWillKnow:Boolean = true;varisTheRightThingToDo:Boolean = false;if (allMyFriendsDoIt && itsJustOne && nobodyWillKnow && isTheRightThingToDo){ trace("I'll do that.");}else{ trace("I will not do something that is not the right thing.");} A. Nothing B. I’ll do that. C. I will not do something that is not the right thing. D. I am so confused right now. I need help.