DMS102/CSC170D: Introduction to Web Development
Spring 2013
Assignment 4: Expressions and Conditions
-
[3 pts] Create a page that (a) asks the user for their favorite
flavor of ice cream; (b) uses the answer in a followup question;
and (c) and displays the answer to that second question.
- [3 pts]
Create a page that asks the user for two numbers (that is, asks
twice for one number each time) and then displays the numbers and
their sum, difference, product, and quotient as a table
in the page.
- [3 pts]
Create a page that asks the user for a number and reports whether
or not the number is even. Hint: Think what it means to be even
and check out the remainder operator (
%
).
- [3 pts]
Fix your script from question 2 so that it displays an appropriate
message for the quotient if the user enters the number 0.
- [3 pts]
Create a page that asks the user for an hour (a number) between 0 and
23 and reports whether the hour corresponds to morning (6-11),
afternoon (12-18), or night (18-23 and 0-5).
- [3 pts]
Create a page that asks the user for their name and their favorite
genre (kind) of music, and then does the following:
- If their favorite style of music is jazz, ask what
instrument they prefer. If the answer is saxophone, ask if they
prefer soprano, alto, or tenor sax.
- If their favorite style of music is classical, ask which
composer they prefer. If the answer is Mozart, ask which piece
is their favorite.
- Otherwise, ask who is their favorite artist.
Have your script produce a nice summary of the answers as the
content of the page.
Things to think about
-
Understand the difference between strings and numbers (even though
Javascript converts many things to strings when necessary).
-
Understand that even though Javascript is
a weakly (or
loosely) typed language, nonetheless values are typed.
-
Check out the
typeof
operator which can be helpful in debugging type problems.
-
Conditional statements are the most basic building block of
programs that do more than one thing.
-
Understand the role of curly braces (
{
and }
) in
delimiting blocks
, especially in if
statements.
-
Understand how to use whitespace (indentation) in your programs to
improve readability, especially of blocks, but realize that
whitespace is almost always not actually meaningful in Javascript
(unlike, say, Python).
Last update: Thursday, 07-Feb-2013 09:41:35 EST