- (1) Write an alarmClock() function that accepts an integer representing the day of the week (Mon=1, Tue=2, ... Sun=7) and returns a string: On weekdays the clock tells us to get up, and weekends it tells us to snooze more. On Monday, the clock adds some extra harassment to get us out of bed.
Examples
alarmClock(2) => Hi ho, hi ho, it's off to school we go...
alarmClock(6) => Hit the snooze button!
alarmClock(1) => Daylight in the swamps! Up and at'em!
Strategy: Use an else-if - _______________________________________________
(2) Write a bowlingScoreFeedback() function that accepts a bowling score 0 .. 300 and returns one of these messages:
300: "most triumphant!"
200..299: "pretty good!"
50..199: "making progress!"
0..49: "better take up Scrabble!"
Examples
bowlingScoreFeedback(250) => pretty good!
bowlingScoreFeedback(25) => better take up Scrabble!
_________________________________
(3) Suppose you want to get a table at a hip restaurant: The variable "style" represents the stylishness of your clothes and "bribe" represents the bribe presented to the Maitre'd.
The Maitre'd is satisfied if style is 8 or more and bribe is 5 or more.
One way to code this up is to write the "satisfied" expression as a straight translation of the problem statement, and then put a ! in front of it://Elevate snoot if not satisfied function maitreD(style, bribe){ if (! ((style >= 8) && (bribe >= 5)) ) { return "tant pis pour vous" else return "Ainsi, s'il vous plaƮt" }
Nov 28, 2010
Final Exam Review Problems
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment