Unit-5-lesson-16-Bubble 5

#1

I may feel stupid after some of you respond but in Unit 5 lesson 16 Bubble 5, the given code is below and we are supposed to find a logic error. I can’t find it. Can someone please explain it to me?

console.log("The maximum of 2 and 3 is " + maxVal(2,3));
console.log("The maximum of 5 and 1 is " + maxVal(5,1));
console.log("The maximum of 8 and 8 is " + maxVal(8,8));

function maxVal(num1, num2){
if (num1 > num2) {
return num1;
}
else if (num1 < num2) {
return num2;
}
}

#2

The code does not check for equality. If you change one of the comparison operators to >= or <=, the program should work correctly. Or you could just change the else if to an else and not check for num1 < num2.

console.log("The maximum of 2 and 3 is " + maxVal(2,3));
console.log("The maximum of 5 and 1 is " + maxVal(5,1));
console.log("The maximum of 8 and 8 is " + maxVal(8,8));

function maxVal(num1, num2){
if (num1 >= num2) {
return num1;
}
else if (num1 <= num2) {
return num2;
}
}

OR

console.log("The maximum of 2 and 3 is " + maxVal(2,3));
console.log("The maximum of 5 and 1 is " + maxVal(5,1));
console.log("The maximum of 8 and 8 is " + maxVal(8,8));

function maxVal(num1, num2){
if (num1 > num2) {
return num1;
}
else {
return num2;
}
}