Read the question, write JavaScript on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read three integers (one per line) and log the largest.
Math.max does this in one call — but try it with plain comparisons too, so you know what it does.
Input. Three lines, each an integer.
Output. One integer: the largest.
Examples
Input
3 9 4
Output
9
Input
5 5 2
Output
5
Hint
- Math.max(a, b, c) returns the biggest.
- By hand: assume a is largest, then compare with b and c.
Show correct code
Peek only after you have tried. You can still Check your own version.
const a = Number(readLine());
const b = Number(readLine());
const c = Number(readLine());
console.log(Math.max(a, b, c));
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.