Making a Choice
Sometimes code needs to decide. We use if and else for that β like a fork in
the road. The word true means yes, and false means no. These yes/no values
are called booleans.
Here a machine checks if a number is positive:
function isPositive(n) {
if (n > 0) {
return true;
} else {
return false;
}
}
Read it as: "if n is greater than 0, return true; else (otherwise) return
false." The > symbol means "greater than."
Your task
Write a function isBig that takes a number n and returns true if n is greater
than 10, and false otherwise. So isBig(20) is true and isBig(3) is false.
β‘ 25 XP
π§± Code blocks
Drag a block into the editor, or tap it to drop it in where your cursor is. Add them in order to build your answer.
solution.jsRuns in your browser
Loading editorβ¦
Tests3 to pass
isBig(20) is true
isBig(3) is false
isBig(10) is false (not greater than 10)
Run your code to check these.