ASDV-WebDev/Semester 1/Assignments/JavaScript/ch03/ex3_11.html

45 lines
1.1 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Example 3.11</title>
<script>
function rateIt()
{
var rate = parseInt(prompt("Rate the site from 1 to 10, with 10 as the best"," "));
var grade = " "
if (rate == 10)
{
grade = "A";
document.write("<p>You gave the site a rating of " + grade + ".</p>");
}
else if (rate >= 7 && rate <= 9)
{
grade = "B";
document.write("<p>You gave the site a rating of " + grade + ".</p>");
}
else if (rate >= 4 && rate < 7)
{
grade = "C";
document.write("<p>You gave the site a rating of " + grade + ".</p>");
}
else if (rate >= 1 && rate <4)
{
grade = "D";
document.write("<p>You gave the site a rating of " + grade + ".</p>");
}
else
document.write("<p>Invalid entry</p>");
}
</script>
</<head>
<body>
<table align ="center" width ="70%"><tr><td>
<h1>&nbsp;</h2>
<h1>Rate the Site</h1>
<h3>Rate the site from 1 to 10, with 10 as the best ever and 1 as one of the worst</h3>
<p><input type="button" id="rating" value="Enter your rating now" onclick="rateIt();" /></p>
</td></tr></table></body>
</html>