eze
May 10, 2019, 6:01pm
1
Tell us what’s happening:
Hey
code seems to be working, at least console shows the correct letter to return…
Problem is my code won’t pass the tests.
What could be the problem?
Your code so far
function fearNotLetter(str) {
let a="";
for(let x=0;x<str.length-1;x++){
if( str.charCodeAt(x+1)!=str.charCodeAt(x)+1 ){
let a=String.fromCharCode(str.charCodeAt(x)+1);
console.log(a)
}else a=undefined;
}
return a;
}
fearNotLetter("bcdf");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters
ILM
May 10, 2019, 6:12pm
2
eze:
else a=undefined;
Your issue is this
Add console.log(a)
right above the return statement
And check your code with this tool
http://pythontutor.com/javascript.html
You really need small tweaks, almost there
1 Like
eze
May 10, 2019, 6:19pm
3
ILM:
console.log(a)
got it!
function fearNotLetter(str) {
let a="";
for(let x=0;x<str.length-1;x++){
if( str.charCodeAt(x+1)!=str.charCodeAt(x)+1 ){
a=String.fromCharCode(str.charCodeAt(x)+1);
console.log(a)
return a;
}else {a=undefined;}
}
console.log(a)
}
fearNotLetter("abcdefghjklmno");
ILM
May 10, 2019, 6:28pm
4
It passes the tests, but it can still be better
For example, if the declaration of a
would give it the value of undefined
you can remove the else statement
1 Like
eze
May 10, 2019, 6:50pm
5
thanks for the tips!
any help is appreciated.
also, while I’m thinking about these algorithms, I sometimes wonder if I should be using any “intermediate” programming stuff, such as Objects, Functions. I tend to go for the basic solution…
ILM
May 10, 2019, 6:53pm
6
Basic is perfect!
You may want to try to come up with two or three different solutions for these things if you feel like it, to familiarise with different things