Ad

HTML Alert Usage Issue

- 1 answer

Hello I am having the current problem of my webpage not loading with two alert dialog boxes, when I comment out the second box and its line of code the webpage works but adding the second box causes the whole page to not work.

<!DOCTYPE html>
<!--Jason Guerrier 2-7-16-->

<html>
        <head>
                <title> Jason Guerrier </title>
        </head>
        <body>
                <script>
                        var userAge = 0;
                        var value1 = 0;
                        var value2 = 0;
                        var add = 0;
                        var sub = 0;
                        var mul = 0;
                        var div = 0;
                        var mod = 0;

                        var equ;
                        var notEqu;
                        var greTha;
                        var greThanEqu;
                        var lesTha;
                        var lesThaEqu;
                        var equEqu;
                        var notEquEqu;

                        userAge = prompt("Enter your age.");
                        if(userAge >= 18)
                            {
                                alert("You are old enough to vote");
                            }
                        else
                            {
                                alert("Unfortunately you are not old enough to vote");
                            }

                        value1 = prompt("Enter a whole number");
                        value2 = prompt("Enter a second whole number");

                        add = parseFloat(value1) + parseFloat(value2);
                        sub = value1 - value2;
                        mul = value1 * value2;
                        div = value1 / value2;
                        mod = value1 % value2;

                        alert("Result of value 1 + value 2 = " + add + 
                        '\n' + "Result of value 1 - value 2 = " + sub + '\n'
                        + "Result of value 1 * value 2 = " + mul + '\n' +
                        "Result of value 1 / value 2 = " + div + '\n' + 
                        "Result of value 1 % value 2 = " + mod);

                        equ = value1 == value2;
                        notEqu = value1 != value2;
                        greTha = value1 > value2;
                        greThanEqu = value1 >= value2;
                        lesTha = value1 < value2;
                        lesThaEqu = value1 <= value2;
                        equEqu = value1 === value2;
                        notEquEqu = value1 !== value2;

                        alert("Result of value 1 == value 2 = " + equ + 
                        '\n' + "Result of value 1 != value 2 = " + notEqu + '\n'
                        + "Result of value 1 > value 2 = " + greTha + '\n' +
                        "Result of value 1 >= value 2 = " + greThanEqu + '\n' + 
                        "Result of value 1 < value 2 = " + lesTha + '\n'
                        "Result of value 1 <= value 2 = " + lesThaEqu + '\n' +
                         "Result of value 1 === value 2 = " + equEqu + '\n' + 
                         "Result of value 1 !== value 2 = " + notEquEqu);

                </script>
        </body>
</html>
Ad

Answer

The error you are getting is:

Uncaught SyntaxError: missing ) after argument list

because you are missing a + operator:

Before:

alert("Result of value 1 == value 2 = " + equ + '\n' +
"Result of value 1 != value 2 = " + notEqu + '\n' +
"Result of value 1 > value 2 = " + greTha + '\n' +
"Result of value 1 >= value 2 = " + greThanEqu + '\n' +
"Result of value 1 < value 2 = " + lesTha + '\n' // Missing operator here
"Result of value 1 <= value 2 = " + lesThaEqu + '\n' +
"Result of value 1 === value 2 = " + equEqu + '\n' +
"Result of value 1 !== value 2 = " + notEquEqu);

After:

alert("Result of value 1 == value 2 = " + equ + '\n' +
"Result of value 1 != value 2 = " + notEqu + '\n' +
"Result of value 1 > value 2 = " + greTha + '\n' +
"Result of value 1 >= value 2 = " + greThanEqu + '\n' +
"Result of value 1 < value 2 = " + lesTha + '\n' + // All fixed!
"Result of value 1 <= value 2 = " + lesThaEqu + '\n' +
"Result of value 1 === value 2 = " + equEqu + '\n' +
"Result of value 1 !== value 2 = " + notEquEqu);
Ad
source: stackoverflow.com
Ad