Tell us what’s happening:
I am trying my best to understand what is going on, following in my example of code, before checking typeof
I was getting all test passed expect 2, by putting typeof
all test failed expect 2.
I am confused because I do not want to use typeof
because it if num
is not a numeric, it should go straight to else which is to print string as it is.
What am I missing? One side I am addicted to doing these all day and one side I get stuck in these small things
Your code so far
function truncateString(str, num) {
if(typeof num == 'Number' && num > 0){
console.log(`${str.slice(0,num)}...`)
return `${str.slice(0,num)}...`
}else{
console.log(num,"><")
return str
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Truncate a String
Link to the challenge: