2

Trying to create a script that asks a user for a range of positive inputs and ends when a negative input is introduced. Then prints the sum and average of the inputs in an alert. Any idea why I'm getting an error on my if statement?

var value;
var sum = 0;
var HTMLout;
var i = 0;

do {

    if(isNaN(value) {
        alert("Enter a positive integer");
    } else {
        value = parseInt(prompt("Enter a positive integer", "Enter a negative integer to quit"));
        sum += value;
        i++;
    }

} while(value != -1);

HTMLout += alert("The sum of these numbers is " + sum);
HTMLout += alert("The average of these numbers is " + sum/i);
1
  • 1
    What kind of an error? Please include that info, too, it will help with identifying the problem, thanks! Commented Feb 2, 2016 at 10:44

3 Answers 3

2

You forgot a closing bracket:

if(isNaN(value)

should be

if(isNaN(value))
Sign up to request clarification or add additional context in comments.

Comments

2

Syntax Error.

Change if(isNaN(value) to if(isNaN(value))

------------------------------------------------------------^ Missing Parenthesis

Comments

0

It is a syntax error
You forgot to place the ending parenthesis. Change if statement to the below code

if(isNaN(value))
{
    alert("Enter a positive integer");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.