I have a problem building a simple prompt message that will ask the user the ff.
First no.
Second No.
Operator being used + - * / %

So far, i have this codes:

Kindly help me.. Thaaanks!

<html>
<body>
<script type="text/javascript">

var num1, num2, ope, sum, diff, prod, quo, mod;
num1=Number(prompt("Enter First number: "));
num2=Number(prompt("Enter Second number: "));
ope=Operators(prompt("Choose Operator : + - * / %"));

if (ope==+)
{
sum=num1+num2;
document.write("The sum is: "+sum);
}

else if (ope==-)
{
diff=num1-num2;
document.write("The difference is: "+diff);
}

else if (ope==*)
{
prod=num1*num2;
document.write("The product is: "+prod);
}

else if (ope==/)
{
quo=num1/num2;
document.write("The quotient is: "+quo);
}

else if (ope==%)
{
mod=num1%num2;
document.write("The remainder is: "+mod);
}

else
{
document.write("INVALID!");
}

document.write("First Number: "+num1);
document.write("<br>");
document.write("Second Number: "+num2);
document.write("<br>");
document.write("Operator Used: "+operator);

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

You must quote operators
if (ope=='+')
there no operators function

<html>
<body>
<script lang="text/javascript">

var num1, num2, ope, sum, diff, prod, quo, mod;
num1=Number(prompt("Enter First number: "));
num2=Number(prompt("Enter Second number: "));
ope=prompt("Choose Operator : + - * / %");

if (ope=='+')
{
sum=num1+num2;
document.write("The sum is: "+sum);
}

else if (ope=='-')
{
diff=num1-num2;
document.write("The difference is: "+diff);
}

else if (ope=='*')
{
prod=num1*num2;
document.write("The product is: "+prod);
}

else if (ope=='/')
{
quo=num1/num2;
document.write("The quotient is: "+quo);
}

else if (ope=='%')
{
mod=num1%num2;
document.write("The remainder is: "+mod);
}

else
{
document.write("INVALID!");
}

document.write("<br>First Number: "+num1);
document.write("<br>");
document.write("Second Number: "+num2);
document.write("<br>");
document.write("Operator Used: "+ope);

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

You must quote operators
if (ope=='+')
there no operators function

<html>
<body>
<script lang="text/javascript">

var num1, num2, ope, sum, diff, prod, quo, mod;
num1=Number(prompt("Enter First number: "));
num2=Number(prompt("Enter Second number: "));
ope=prompt("Choose Operator : + - * / %");

if (ope=='+')
{
sum=num1+num2;
document.write("The sum is: "+sum);
}

else if (ope=='-')
{
diff=num1-num2;
document.write("The difference is: "+diff);
}

else if (ope=='*')
{
prod=num1*num2;
document.write("The product is: "+prod);
}

else if (ope=='/')
{
quo=num1/num2;
document.write("The quotient is: "+quo);
}

else if (ope=='%')
{
mod=num1%num2;
document.write("The remainder is: "+mod);
}

else
{
document.write("INVALID!");
}

document.write("<br>First Number: "+num1);
document.write("<br>");
document.write("Second Number: "+num2);
document.write("<br>");
document.write("Operator Used: "+ope);

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

ThankYouuuuuu! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.