1. Modify Example 19.7 [20 points] A. combine three loops into one loop. B. Use
ID: 3730542 • Letter: 1
Question
1. Modify Example 19.7 [20 points] A. combine three loops into one loop. B. Use "while loop" to replace the "for loop" and maintain the same function. XXXX=also I need to keep the same formatting as the for functions in the same order
2. Modify the Example 19.8 - new program. [20 points] A. Use confirm function to always ask if the user wants to continue before the program ends. B. If the user click OK button, the program should start again. C. If the user click Cancel button, then the program ends and output (alert()) "See you next time" message.
19.7
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
19.8
<html>
<head>
<title>JavaScript Sort Program</title>
<script language="javascript">
do{
lc = true;
got = prompt ("Would you like to continue");
answer = confirm ("You input: " + got + ". Is this correct?");
if (answer == true){
var ck = isNaN(got);
if (ck == true)
alert(got + " is not a number");
else{
alert ("Your number squared = " + got*got);
lc = false;
}// end if
} // end if
} while (lc == true)
</script>
</head>
<body>
</body>
</html>
Explanation / Answer
<html>
<head>
<title>JavaScript Sort Program</title>
<script language="javascript">
do{
lc = true;
got = prompt ("Would you like to continue");
answer = confirm ("You input: " + got + ". Is this correct?");
if (answer == true){
var ck = isNaN(got);
if (ck == true)
alert(got + " is not a number");
else{
alert ("Your number squared = " + got*got);
}// end if
} // end if
lc = confirm("Do you want to continue?");
// confirm function will promt the user , if user click ok than it will return true if user click cancle than it will return false, so here lc will store the return value
// if it is true than it will continue and it is false loop get terminated after coming out of the loop we will print see you next time using alert() function
} while (lc == true)
alert("See you next time");
</script>
</head>
<body>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.