The challenge
Write biggest(a, b, c) that returns the largest of three numbers. Use if statements or comparisons, not Math.max.
Try it
Write your answer below, then press Check my answer. Your code runs right here in your browser, and the tests tell you what works.
It prints
What the tests check
biggest(1, 2, 3)gives3biggest(9, 2, 3)gives9biggest(4, 8, 6)gives8biggest(-1, -5, -3)gives-1biggest(5, 5, 2)gives5
Hints
Stuck? Open one hint at a time. Try again after each one.
Hint 1
Keep a variable best = a, then replace it if b or c is bigger.
A solution
There’s always more than one right way. Read it, make sure you understand it, then try writing it yourself without looking.
Show one possible solution
function biggest(a, b, c) {
let best = a;
if (b > best) best = b;
if (c > best) best = c;
return best;
}
Learn what you need
This exercise uses what Grade 4: Making Decisions: if, else & Friends teaches. Read those notes first if any of it is new.