Image

Imagenathanmm wrote in Imagejavascript awry

Listens: Elliott Smith- Clementine

For structure

Here's my code. I need this to add 10 numbers, average them and find the largest and smallest entries using the FOR statement. Any help would be appreciated. Also. If anyone has suggestions on how to structure a program that will allow the user to enter a five-digit number and tell if it's a palindrome let me know. Thanks, nathan M.

<SCRIPT LANGUAGE = "JavaScript">

  

  var largest, smallest, total, average, first_time;

  first_time = true;

  for ( var counter = 1; counter <= 10; ++counter )

    

    

    num1 = window.prompt("Please enter a number", "0");

    int1 = parseInt (num1);

    total = int1;

    if (first_time = true){

      largest = int1;

      smallest = int1;

      total = int1;

      first_time = false; }

    if (int1 < smallest)

      smallest = int1;

    if (int1 > largest)

      largest = int1 ;

    

    total = total + int1;

    average = total / 10;

    document.writeln( "Largest number is: " + largest);

    document.writeln( "Smallest number is: " + smallest);

    document.writeln( "The average of all numbers is: " + average);



</SCRIPT>