Practice exercise - Functions & Arrays 38

I got a problem with the exercise number 38 (Functions & Arrays).
The solution is:

function longerThanNumber(string, number) {
let answer = (string.length > number);
return answer;
}

but when I try and console.log(answer); the program says that answer is not defined. I don’t get it - Answer IS defined and returned from the function. Maybe I am blind to see what’s wrong, but that’s not too much code I think :smiley:

1 Like

You just need to console.log(longerThanNumber("test", 3)) the function.

Carlos Z.

2 Likes

Exercise 38

Hi Carlos,

Why is the answer key true to only when we input a single-digit number in the function?

But when I tried inputting numbers with more than one digit, it returned false although
the length of the string is actually longer than that of the number?

Is there something wrong with the answer key or did I misunderstand something?

Hey @BUILTOCKCHAIN, hope you are ok.

I dont see any issue with the code, it means to compare if the amount of letters of a word (string.length) is higher than a number inputed. So based on the calculation of both, it will mention if its true (amount of words are higher than number) or false.

image

Carlos Z