/*Creates a string varible called strWeather with a blank intial value*/ var strWeather = new String(""); /*Creates a number varible called intTemperature with an intial value of zero*/ var intTemperature = new Number(0); /*Prompts the user to input the weather. Give the user choice of Sunny, rainy, or snowy.*/ strWeather = window.prompt("What is today's weather (sunny, rainy or snowy)?", ""); /*Prompts the user to input the temperature.*/ intTemperature = window.prompt("What is today's temperature?", ""); /*Converts whatever is in strWeather to uppercase*/ strWeather = strWeather.toUpperCase(); /*Since input value are always strings, intTemperature needs to be converted to an Integer so it can work in the comparisons.*/ intTemperature = parseInt(intTemperature); /*If strWeather is equal to rainy and intTempearture is less than 50, display a dialog box that says, "You'd better bring an umbrealla and a heavy, winter coat."*/ if(strWeather == "RAINY" && intTemperature <= 50) { window.alert("You'd better bring an umbrella and wear a heavy, winter coat."); } /*If strWeather is equal to rainy and intTempearture is between 70 and 50, display a dialog box that says, "You should bring an umbrella and wear a light jacket."*/ else if(strWeather == "RAINY" && intTemperature < 70 && intTemperature > 50) { window.alert("You should bring an umbrella and wear a light jacket."); } /*If strWeather is equal to rainy and intTempearture is higher than 70, display a dialog box that says, "You should bring an umbrella and wear shorts."*/ else if(strWeather == "RAINY" && intTemperature >= 70) { window.alert("You should bring an umbrella and wear a shorts."); } /*If strWeather is equal to snowy and intTempearture is less than 50, display a dialog box that says, "You should bring an umbrella and wear a heavy, winter coat."*/ else if(strWeather == "SNOWY" && intTemperature <= 50) { window.alert("You'd better bring an umbrella and wear a heavy, winter coat."); } /*If strWeather is equal to snowy and intTempearture is between 70 and 50, display a dialog box that says, "You should bring an umbrella and wear a light jacket."*/ else if(strWeather == "SNOWY" && intTemperature < 70 && intTemperature > 50) { window.alert("You should bring an umbrella and wear a light jacket."); } /*If strWeather is equal to snowy and intTempearture is greater than 70, display a dialog box that says, "You should bring an umbrella and wear shorts."*/ else if(strWeather == "SNOWY" && intTemperature >= 70) { window.alert("You should bring an umbrella and wear a shorts."); } /*If strWeather is equal to sunny and intTempearture is greater than 70, display a dialog box that says, "You should bring sunglasses and wear shorts."*/ else if(strWeather == "SUNNY" && intTemperature >= 70) { window.alert("You should bring sunglasses and wear shorts."); } /*If strWeather is equal to sunny and intTempearture is between 70 and 50, display a dialog box that says, "You should bring sunglasses and wear a light jacket.*/ else if(strWeather == "SUNNY" && intTemperature < 70 && intTemperature > 50) { window.alert("You should bring sunglasses and wear a light jacket."); } /*If strWeather is equal to sunny and intTempearture is less than 50, display a dialog box that says, "You should bring sunglasses and wear a heavy, winter coat.*/ else if(strWeather == "SUNNY" && intTemperature <= 50) { window.alert("You should bring sunglasses and wear a heavy winter coat."); } /*If the user types something that does not fit into the above categories, display a mesage that tells them to start over.*/ else { window.alert("I think you spelled something incorrectly. Press F5 and try again.") }
Site hosted by Angelfire.com: Build your free website today!