Anonymous user
Arithmetic/Integer: Difference between revisions
m
→{{header|JavaScript}}: spidermonkey's javascript implementation has print/readline
Underscore (talk | contribs) m (→{{header|Perl 6}}: Spelling.) |
m (→{{header|JavaScript}}: spidermonkey's javascript implementation has print/readline) |
||
Line 446:
=={{header|JavaScript}}==
In order to get user input, this solution {{works with|JScript}} or {{works with|SpiderMonkey}}, however the arithmetic operators are the same for any version of JavaScript.
Note that JavaScript division returns a float, even if the operands are integers.
<lang javascript>
WScript.Echo(prompt);▼
return WScript.StdIn.readLine();▼
}▼
var b = parseInt(get_input("Enter an integer"), 10);
Line 463 ⟶ 458:
WScript.Echo("product: a * b = " + (a * b));
WScript.Echo("quotient: a / b = " + (a / b));
WScript.Echo("remainder: a % b = " + (a % b));
function get_input(prompt) {
output(prompt);
try {
▲ return WScript.StdIn.readLine();
} catch(e) {
return readline();
}
▲}
function output(prompt) {
try {
▲ WScript.Echo(prompt);
} catch(e) {
print(prompt);
}
}</lang>
output:
<pre>Enter an integer▼
▲Enter an integer
-147
Enter an integer
|