I've this little code:
var mobili='mqihfdbacegklnprtuz&xyso';
function encrypt(index){
if(mobili.includes(index)){
var test = "It's working";
console.log(test)
}
else{
var test = "Bueller? Bueller?";
console.log(test);
}
}
console.log(encrypt('j'));
So... This code works but the output get to me the "undefined" value too. Why?
PS: I'm in repl.it website to run this one.
Your function isn't return
ing anything - it's actually calling console.log
itself. You can fix this in two ways:
One: Add a return
statement to your function instead of using console.log
:
function encrypt(index){
if(mobili.includes(index)){
var test = "It's working";
}
else{
var test = "Bueller? Bueller?";
}
return test;
}
Two: Call the function without using console.log
:
encrypt('j');