Tell us what’s happening:
The below code seems to pass the challenge as it returns the exact alphabet the challenge needs but it doesn’t pass. I suspect it is because I return the key of the object which might not count as a string. However when I check the output in the console, my result is not an array or object key, it is shown as a string. Is this a fair answer to the challenge?
Your code so far
function fearNotLetter(str) {
let alpha = {
a : 0 ,
b : 1 ,
c : 2 ,
d : 3 ,
e : 4 ,
f : 5 ,
g : 6 ,
h : 7 ,
i : 8 ,
j : 9 ,
k : 10 ,
l : 11 ,
m : 12 ,
n : 13 ,
o : 14 ,
p : 15 ,
q : 16 ,
r : 17 ,
s : 18 ,
t : 19 ,
u : 20 ,
v : 21 ,
w : 22 ,
x : 23 ,
y : 24 ,
z : 28
}
console.log();
for (let i = 0; i < str.length ;i++){
console.log((alpha[str[i+1]]) + "-" + (alpha[str[i]]) + " deduction is " + (alpha[str[i+1]] - alpha[str[i]]));
if (alpha[str[i+1]] - alpha[str[i]] == 1 ){
console.log("we are at " + Object.keys(alpha).filter(function (key){ return alpha[key] === alpha[str[i]]}));
}
else if (alpha[str[i+1]] - alpha[str[i]] == 2 ) {
return Object.keys(alpha).filter(function (key){ return alpha[key] === (alpha[str[i]] + 1)});
}
else {
console.log("undefined");
return undefined;
}
console.log("end round" + i);
}
}
console.log(fearNotLetter("bce"));
console.log(fearNotLetter("abcdefghjklmno"));
console.log(fearNotLetter("stvwx"));
console.log(fearNotLetter("abcdefghijklmnopqrstuvwxyz"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36
.
Link to the challenge: