* fix: added info and solutions for stubs * fix: made title match main header * fix: removed wrong closing tag Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added closing tag Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: corrected solution Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: changed verbiage Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added code tags Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: added solution
1.3 KiB
1.3 KiB
title
title |
---|
Comparison with the Greater Than Operator |
Comparison with the Greater Than Operator
Problem Explanation
· Add the greater than
operator to the indicated lines so that the return statements make sense.
Hints
Hint 1
The greater than operator (>)
compares both operands using type coercion (converting data types if necessary) and returns true
if the first one is greater than the second one.
Solutions
Solution 1 (Click to Show/Hide)
function testGreaterThan(val) {
if (val > 100) {
// Change this line
return "Over 100";
}
if (val > 10) {
// Change this line
return "Over 10";
}
return "10 or under";
}
// Change this value to test
testGreaterThan(10);
Code Explanation
The function first evaluates if
the condition (val > 100)
evaluates to true
converting val
to a number if necessary. If it does, it returns the statement between the curly braces ("Over 100"). If it doesn't, it checks if the next condition is true
(returning "Over 10"). Otherwise the function will return "10 or under".