JavaScript bootcamp · Lab 06

Largest of three

easyIf Else10 minLesson: If Else

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

Example 1
Input
3
9
4
Output
9
Example 2 — Ties are fine.
Input
5
5
2
Output
5
Hint
  1. Math.max(a, b, c) returns the biggest.
  2. 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.