any help would be appreciated. I can't figure out what I'm doing wrong. I know it's probably something simple, I'm learning, just slowly... I have 2 tests of the code I was trying to get to work. It's basically just if else statements and then posting the results in a div. I just can't get it to work. Any advice would be grateful! Thank you.
<html>
<head>
<meta charset="ISO-8859-1">
<title>WindChill</title>
</head>
<script>
function DetermineDanger(){
// This function should take in the user input from the textBox with id="windchillTxt"
// Save the user input in a local variable called windchill, be sure to use parseFloat
// Then using a conditional structure determine the appropriate warning to display based on windchill
// The result should be displayed in the <div> with id="displayDiv"
//test 1
//var windchill
//number = parseFloat(document.getElementById('windchillTxt').value);
//if (windchill <= -60)
//document.getElementById('displayDiv').innerHTML = 'Extreme Danger, frostbite could occur within 5 minutes';
//else if (windchill <= -45)
//document.getElementById('displayDiv').innerHTML = 'Danger, frostbite could occur within 10 minutes';
//else if (windchill <= -25)
//document.getElementById('displayDiv').innerHTML = 'Caution, frostbite could occur within 30 minutes';
//else
//document.getElementById('displayDiv').innerHTML = 'Just really cold! Be sure to bundle up!';
//test 2
var windchill
number = parseFloat(document.getElementById('windchillTxt').value);
if (windchill <= -60) {
document.getElementById('displayDiv').innerHTML = 'Extreme Danger, frostbite could occur within 5 minutes';
}
else {
if (windchill <= -45) {
document.getElementById('displayDiv').innerHTML = 'Danger, frostbite could occur within 10 minutes';
}
else {
if (windchill <= -25) {
document.getElementById('displayDiv').innerHTML = 'Caution, frostbite could occur within 30 minutes';
}
else {
document.getElementById('displayDiv').innerHTML = 'Just really cold! Be sure to bundle up!';
}
}
}
}
</script>
<body>
<h1>Wind Chill Danger</h1>
Enter windchill:<input id="text" id="windchillTxt"><br>
<!-- Finish the onclick handler with a function call -->
<input type="button" value="Information" onclick="DetermineDanger();">
<hr>
<div id="displayDiv"></div>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire