Variables
prompt.js
weetbix = prompt("How many Weet-Bix did you eat?"); alert("Wow, you ate " + weetbix + ", that's amazing!");
letters.js
uni = "Queensland University of Technology"; streetAddress = "2 George Street"; city = "Brisbane"; state = "QLD"; postcode = "4000"; studentName = prompt("Who are you writing a letter to?"); alert( studentName + "\n" + streetAddress + "\n" + city + " " + state + " " + postcode );
numbers.js
multiplyer = 9; luckyNumber = prompt("What is your lucky number?"); result = multiplyer * parseInt(luckyNumber); alert("Your lucky number multiplied by nine is: " + result);
- Make a script that reads in my name and says
Hello, Alfred
, where Alfred was the name I initially entered. - Continue your script that stores my age (as well as my name). These questions should be asked separately. Once I have entered my name and age, your program should output
Hello, Sally, you are 17 years old.
, where Sally was the name I entered, and 17 was the age I also entered. - Finally, after you have asked me for my name and age, ask how my day is going. No matter what I say, make sure your script responds
OK, I understand, try and have a good night's sleep!
- Rewrite the address label maker script, so that it will work for any address.
- Using the numbers script, write your own script that will calculate the area of a square from the length of a side value that I input. For example, your program should prompt
Enter the length of a square
, and if I answer 4, the program should sayThe area of the square is 16.
- Create a small script that asks me for any two numbers. The program should then calculate and output the sum, product, difference and quotient (i.e. plus minus times divide) of the two numbers I originally input.
- Create a lap timer that times 3 laps of a running track. After I enter my 3 lap times, the computer should calculate the average lap time (of all laps), then tell me whether each lap I ran was above or below the average lap time.
To read in a floating point value, you may need to useparseFloat
as shown in the following example:
firstLap = parseFloat(prompt("Enter first lap time: "));