Javascript Compare Two Integers
Write a script that asks the user to enter two integers, obtains the numbers from the user and outputs text that displays the larger number followed by the words "is larger" in an alert dialog. If the numbers are equal, output XHTML text that displays the message "These numbers are equal."
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Exercise 6.17 Compare Them</title>
<script type="text/javascript">
<!--
var firstnum;
var secondnum;
firstnum = window.prompt("Enter any Integer Value:");
secondnum = window.prompt("Enter any second Integer Value:");
var first = parseInt(firstnum);
var second = parseInt(secondnum);
if(first>second)
{
window.alert( first + " is Larger than " + second );
}
else if(second>first)
{
window.alert( second + " is Larger than " + first );
}
else
{
window.alert( first + " is equal to " + second );
}
// -->
</script>
</head>
<body>
</body>
</html>
1 Response to Javascript Compare Two Integers
Prompt and get student’s name
Prompt and get student’s quiz marks
If quiz marks is between 10 to 30, then print “Awesome!”
But if the quiz is below 10, then print “Study harder!”
Write a full HTML with Javascript codes for the above problem.
Something to say?