Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, i been working on this JAVASCRIPT-CONTROL STATEMENTS program, but need so

ID: 3930282 • Letter: H

Question

Hello, i been working on this JAVASCRIPT-CONTROL STATEMENTS program, but need some assistance. Can anybody give me a hand please?

1. I need to create a LOOP that lets the user enter a series of integers. The user should enter 99 to terminate the loop. After all the numbers have been entered, the program should display the largest and smallest numbers entered.

2.Validate input when the user never uses the program i.e. they type -99 to quit when the program first launches. Below is example input and output

3..Make sure the program validates input by displaying a message if the numbers are the same, once the program has been terminated.

0. My Code

<!DOCTYPE html>

<html>
   <head>
      <meta charset = "utf-8">
      <title> assignment4 </title>
      <script>
          
       var smallest = 0;
       var largest= 0;
       var student=1;
       var result;
      
      
       while (student <=99){
          
       result = window.prompt("enter a number of -99 to quit");
          
           if(result == "1")
           smallest++;
           else
           largest++;
          
           student++;
          
           document.writeln("smallest:"+ smallest);
           document.writeln("<br/>");
           document.writeln("largest:"+ largest);
       }
              
      </script>
   </head> <body></body>
</html>


  
     
    
     
  

  
     
    
     
  

--------------------------EXAMPLE TO DISPLAY:

1:

-5

5

9

-99

SMALLEST : -5

LARGEST: 9

EXAMPLE:

2: -99

YOU TERMINATED THE PROGRAM!

3:

-5

-5

-99

SMALLEST: -5

LARGETS: =5

THE NUMBERS ARE THE SAME!

Explanation / Answer

<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title> assignment4 </title>
<script>
// set smallest number to +infinity and largest to -infinity
var smallest = Number.POSITIVE_INFINITY;
var largest= Number.NEGATIVE_INFINITY;
       var student = 0;
var result;
       // while result != -99
while (true){
           result = window.prompt("enter a number of -99 to quit");
           // convert string to integer.
           // check largest and smallest based on the conditions
result = parseInt(result);
           if(result == -99){
               break;
           }
if(result>largest)
               largest = result;
if(smallest > result)
               smallest = result;
           student = student + 1;
}
       // write to html
       if(student==0){
           document.writeln("YOU TERMINATED THE PROGRAM!");
       }
       else{
           document.writeln("smallest:"+ smallest);
           document.writeln("<br/>");
           document.writeln("largest:"+ largest);   
           if(smallest == largest){
               document.writeln("<br/>THE NUMBERS ARE THE SAME!");
           }
       }
</script>
</head> <body></body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote