Nov 28, 2010

Final Exam Review Problems

final exams
  • (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"
    }

Jul 14, 2010

Jimi Hendrix in JavaScript




ifSixWasNine, by Jared (a.k.a. "Jimi" ;-) Hendricks

ifSixWasNine(6) ==> 9
ifSixWasNine(12) ==> 18

Exercise: Write and test this function.

Jul 12, 2010

xhtml: logical vs physical tags

HTML includes two types of Style Tags:
  • logical (a.k.a. phrase elements)
    tag the information according to its meaning (e.g., abbr, acronym, code, etc.)
  • physical
    tag the exact appearance of the information (i.e. b, i, etc.)
Both <em> and <i> display italics. CSS is the preferred way to style content rather than logical tags. Logical style tags are preferred over physical tags (which is why the latter are deprecated in xhtml).

Rationale: the goal in xhtml is to separate structure elements from style elements, and remove the latter from html. Content should be styled with CSS rather than html. Logical tags describe the structure or semantics of content and are, therefore, preferred over style elements like <b> and <i>.