0

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>
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by choboja621
0

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>

Edited by urtrivedi: n/a

0

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! :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.