Using FrontPage, write the HTML file to create a web page similar to
the one below (don't worry about the border, it's there only to outline the
page):
Note: The form is named pokerForm. The text boxes are named
card1box, card2box, card3box, card4box, and
card5box. The 2 radio buttons under card 1 are named card1,
the 2 radio buttons under card2 are named card2 and so on. If a user
clicks the "Draw Cards" button the function named replaceCards should
be called (but do not worry about defining this function, just make sure
that it gets called when the top button gets clicked). The form above shows
the initial contents of the page when it loads (so the cards shown should
be displayed when the page loads).
Here's the solution, you'll have top view its source
to see the HTML.
Write a (very odd) version of the replaceCards function for
the form above. It will ignore all the radio buttons and simply ask the user
for a number from 1 to 10 (with a prompt command). If the number they enter
is from 3 to 7 (inclusive), change the value displayed for the second card
to "Qd", otherwise, change the 10 and Jack of diamonds to the 7 of clubs and
7 of hearts respectively.
function replaceCards(){ var num = prompt("Enter a
number from 1 to 10",""); num = parseFloat(num); if ( (num < 1) || (num
> 10)){ num
= prompt("I said from 1 to 10, try again!",""); } if ( (num >= 3) &&
(num <= 7) ){ document.pokerForm.card2box.value="Qd"; } else { with
(document.pokerForm){
card3box.value = "7c";
card1box.value = "7h"; } } }
Given the form below (with the names corresponding in the obvious
way to the various form elements), what (exactly) gets displayed by the JavaScript
statements:
var theName = document.myForm.nameBox.value; var n1 = document.myForm.number1Box.value; var n2 = document.myForm.number2Box.value; document.write("Hi " + theName + "your sum is " + n1 + n2 + "<BR>Have
a great day!");
The result is:
Hi Tom Lintonyour sum is 1255
Have a great day!
Assume that the form above has a push-button whose onClick attribute
calls the function work(). Also assume there is a multi-line text
area (at the bottom of the form) named output. Write the JavaScript
statements needed to define the work function, so that when the user
clicks the button, a message similar to:
Thanks for shopping at Grandma Lumpits Tom Linton.
You ordered:
--12 chocolate chip cookies
--55 biscuits
and your total is $5.0
gets printed in the multi-line text area named output. Note: the bold
quantities above are replaced by (non-bold versions of) their entries in
the form. The cookies are .05 each and the biscuits are .08 each. By sure
to have the newlines present in the output.
function work() { with (document.myForm){ var
name = nameBox.value; var
numCookies = parseFloat(number1Box.value); var
numBiscuits = parseFloat(number2Box.value); } var message = "Thanks for
shopping at Grandma Lumpits " + name + "\n"; message = message + "You
ordered:\n"; message = message + "--"
+ numCookies + " chocolate chip cookies\n"; message = message + "--"
+ numBiscuits + " biscuits\n"; message = message + "and
your total is $" + (.05*numCookies + .08*numBiscuits); document.myForm.output.value
= message; }
Write a JavaScript statement that sets the background color of the
web page to #CC00AA. document.bgColor
= #CC00AA;
Write JavaScript statements that ask the user for a number form 1
to 50. If they enter a bad value (less than 1, or greater than 50), use an
alert statement to inform them of their mistake and re-ask them for another
value. Their number represents the number of bags of coffee they would like
to buy. Print out a message that tells them their total price ($4 per bag,
plus 6% tax).
var num = prompt("Enter a number from 1 to
50",""); num = parseFloat(num); if ( (num < 1) || (num>50) ){ alert("I said from 1 to 50.
Once more smoothy."); num = prompt("Enter a number
from 1 to 50",""); num = parseFloat(num); } var cost = 4*num; cost = cost + cost*.06; document.write("Your " + num + " bags of coffee
have a total price of"); document.write(" $" + cost + ".");
Write a JavaScript statement that sends the user back 2 windows in
their browser's history.
window.history.go(-2);
Assume every deck object has:
a boolean property named isShuffled, that is true if the deck
is shuffled and false otherwise;
a number property named numberCardsLeft;
several sub-objects of type card (these are named card1,
card2, etc.), where each card object has
a String called suit (that is "clubs", "diamonds", "hearts"
or "spades");
a number property named face (that is equal to 2, 3, 4, ...
, 13, or 14).
If myDeck and yourDeck are deck objects (or variables) write
JavaScript statements that assign the face of myDeck's card6 to the face of
yourDeck's card2, if card1 in myDeck has a suit equal to hearts. If card1
in myDeck is not a heart, set the isShuffled property of myDeck to true,
and set yourDeck's cardsLeft property to one less than its current value.
if (myDeck.card1.suit == "hearts"){ yourDeck.card2.face = myDeck.card6.face; } else{ myDeck.isShuffled = true; yourDeck.cardsLeft = yourDeck.cardsLeft
- 1; }