5) Write a script that asks a user to input two numbers. Output whether the diff
ID: 3741620 • Letter: 5
Question
5) Write a script that asks a user to input two numbers. Output whether the difference of the first number and the second is positive, negative, or zero. Also make sure that the usei entered a valid numbers.(25 points) Here are some example runs (make sure your program outputs the same exact message) Enter the first number: hello THIS IS NOT A NUMBER Enter the first number: 5 Enter the second number: whatever This is NOT A NUMBER Enter your first number: 5 Enter the second number: 2 The difference is POSITIVE Enter vour first number. 2 Enter the second number: 5 The difference is NEGATIVE Enter your first number: 5 Enter the second number: 5 This difference is ZEROExplanation / Answer
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>Integer Application</title>
<script>
var firstNumber; // first string entered by user
var secondNumber; // second string entered by user
var number1; // first number to add
var number2; // second number to add
var sum; // sum of number1 and number2
var product; //product of number1 and number2
var difference; //difference of number1 and number2
var quotient; //quotient of number1 and number2
// read in first number from user as a string
firstNumber = window.prompt( "Enter first integer" );
if( Number.isInteger(firstNumber)) {
// convert numbers from strings to integers
number1 = parseInt( firstNumber );
// read in second number from user as a string
secondNumber = window.prompt( "Enter second integer" );
if( Number.isInteger(secondNumber)) {
number2 = parseInt( secondNumber );
difference = number1 - number2; //subtract the integers
if(difference > 0) {
document.writeln( "<h1>This difference is POSITIVE </h1>" );
}else if(difference < 0) {
document.writeln( "<h1>This difference is NEGATIVE </h1>" );
}else{
document.writeln( "<h1>This difference is ZERO </h1>" );
}
}else{
document.writeln( "<h1>This is NOT A NUMBER </h1>" );
}
}else{
document.writeln( "<h1>This is NOT A NUMBER </h1>" );
}
</script>
</head><body></body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.