In this lab, you will work with JavaScript flow control statements.
Use File - Close All to close all open editing windows.
In RAD, create a new Dynamic Web Project named Lab12Web associated with Lab12EAR.
In the WebContent folder, create a new HTML File named who-are-you.html with an internal JavaScript.
Complete the script so it:
Uses the prompt() function to ask the user to enter their name:
var name = prompt("Enter your name");
Uses an if-else if- else statement:
If the name is "Sam", write to the document "Hello, Sam!"
If the name is "Sue", write to the document "Goodbye, Sue!"
Any other name, write "Who are you?"
Copy who-are-you.html to who-are-you-switch.html. In the copied file, rewrite it to use the switch-case statement.
Create a new HTML File named measure-distribution.html that uses an external JavaScript that generates 100,000 random numbers and counts how many are greater than 0.5, how many are less than 0.5 and how many are exactly 0.5. Display the results to a Web page.
Hint: The Math.random() method returns a number between 0 and 1.
Write a Javascript program that prompts the user for a string. Your script's job is analyze the characters in the string. Count the number of spaces, punctuation characters and "normal" characters. Display the counts in the Web page.
Hint: Strings have a charAt() method that returns the character at an index in a string. Indexes start at zero.
Write an HTML form and Javascript that lets the user guess a number between 1 and 1000 with a maximum of 10 guesses. The form should contain a text input widget into which user can enter the guess and a submit button. On submission, tell the user whether guess is too high, too low or correct. The page should show the user how many attempts they have left.
To get a random number between 1 and 1000:
var theNumber = Math.floor(Math.random() * 1001);
Extra credit: Disable the submit button after 10 guesses.