Tell us what’s happening:
I have opted to use a for loop on this to iterate through the values, in the description it says no sorting is needed. I use the for loop to check if the next value in the string is just one ascii code away from the current value. if it’s not, I want to push the ascii value +1 to chars. I just need to know how to get the char code from an ascii value. I saw on stack overflow that if it’s a string, I could use the .fromCharCode method but on string.prototype on MDN, I don’t see that being an option. Is there a way to get the character from the ascii code? what data type should I use?
Your code so far
function fearNotLetter(str) {
let test = 'e';
console.log(test.charCodeAt(0));
let chars =[];
for (i=0; i<str.length; i++){
console.log(str.charCodeAt(i)+1);
if (str.charCodeAt(i) + 1 !== str.charCodeAt(i+1)){
console.log('inside the if loop', str.charCodeAt(i), str.charCodeAt(i) + 1);
chars.push(str.charCodeAt(i) + 1);
break;
} console.log('this is chars' + chars);
console.log(chars.fromCharcode(chars));
// so far I have identified that the charCodeAt the missing one is 100. now all I have to do is use fromCharCode at it and it should work.
// chars.push(str.charCodeAt(i));
// }
//console.log(chars.fromCharCode(chars));
// let first = str.charCodeAt(0);
// console.log(first);
// let last = str.charCodeAt(str.length-1);
// console.log(last);
// console.log(chars);
// let answer = str.split("");
// return answer;
} return chars;
}
fearNotLetter("abce");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters/