<html> <title>Welcome!</title> <body> <button onclick="monthProgram()">Days of the Month Remaining</button><br /> <button onclick="converterProgram()">Fahrenheit to Celsius Converter</button><br /> <button onclick="ooeProgram()">Simple Guessing Game</button><br /><script type = "text/javascript">
//Prompts for InfofirstName = prompt("Please enter your first name: "); lastName = prompt("Please enter your last name: ");
//ConcatenatefullName = firstName + " " + lastName; //Start of Programdocument.write("Hello, " + fullName + ". Welcome to my program! Please click a button to get started.");
function monthProgram() {//Days Left in the Month SwitchmonthDay = prompt("Please enter the day of the month: ");whichMonth = prompt("Please enter the month: ");var whichMonth = whichMonth.toLowerCase();
switch (whichMonth) { case "september": daysLeft = 30 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; case "october": daysLeft = 31 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; case "november": daysLeft = 30 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; case "december": daysLeft = 31 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; case "january": daysLeft = 31 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; case "february": daysLeft = 28 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; case "march": daysLeft = 31 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; case "april": daysLeft = 30 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; case "may": daysLeft = 31 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; case "june": daysLeft = 30 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; case "july": daysLeft = 31 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; case "august": daysLeft = 31 - monthDay; alert("There are " + daysLeft + " days left in the month."); break; default: alert("You entered an invalid month."); }
}
function converterProgram() { //Fahrenheit to Celsius Converter function toCelsius(fahrenheit) { return (5/9) * (fahrenheit - 32); }
function toFahrenheit(celsius) { return (9/5) * (celsius + 32); }
do { fahrOrCels = prompt("Enter c to convert celsius and f to convert fahrenheit: "); fahrOrCels = fahrOrCels.toLowerCase(); } while (fahrOrCels != "c" && fahrOrCels != "f");
if (fahrOrCels == "c") {
temperature = prompt("Enter the temperature in celsius: ");
alert("The temperature is " + toFahrenheit(temperature) + " degrees fahrenheit.");
} else if (fahrOrCels == "f") {
temperature = prompt("Enter the temperature in fahrenheit: ");
alert("The temperature is " + toCelsius(temperature) + " degrees celsius.");
} else {
alert("You did not enter a valid character and broke me."); } }
function continuePrompt() { //Continue Prompt wantContinue = prompt("Would you like to continue? :");
if (wantContinue == "yes" || wantContinue == "y") { document.write("Thank you for trying to continue, but this is the end. I have ran out of ideas."); } else if (wantContinue == "no" || wantContinue == "n") { document.write("Thank you for using my program. Goodbye!"); } else { document.write("You entered an invalid character/option and broke me. :c"); }}
function ooeProgram() {
ranNum = Math.random(); ranNum = ranNum.toString(); numGuess = prompt("Guess odd or even: "); var numGuess = numGuess.toLowerCase(); lastDigit = ranNum.slice(-1);
if (numGuess == "odd" || numGuess == "o") { switch (lastDigit) { case "1": alert("Your guess was correct!" + "The number was " + lastDigit + "."); break; case "3": alert("Your guess was correct!" + "The number was " + lastDigit + "."); break; case "5": alert("Your guess was correct!" + "The number was " + lastDigit + "."); break; case "7": alert("Your guess was correct!" + "The number was " + lastDigit + "."); break; case "9": alert("Your guess was correct!" + "The number was " + lastDigit + "."); break; default: alert("Your guess was incorrect." + "The number was " + lastDigit + "."); } }
else if (numGuess == "even" || numGuess == "e") { switch (lastDigit) { case "0": alert("Your guess was correct!" + "The number was " + lastDigit + "."); break; case "2": alert("Your guess was correct!" + "The number was " + lastDigit + "."); break; case "4": alert("Your guess was correct!" + "The number was " + lastDigit + "."); break; case "6": alert("Your guess was correct!" + "The number was " + lastDigit + "."); break; case "8": alert("Your guess was correct!" + "The number was " + lastDigit + "."); break; default: alert("Your guess was incorrect." + "The number was " + lastDigit + "."); } }
else { alert("You entered an invalid option."); }
} </script></body></html>