+ 5
[SOLVED] I need help with JS code
I trying to replace few letter and print changed sentuence. var input = "java script is awesome"; but finished output need to be this: var output = "j4v4 5cr1pt 15 4w350m3" ; I try to change letter using indexes but it dont work. It look like it is not posible to do in that way. Here is code. https://code.sololearn.com/WX4qDDOcrChd/?ref=app
8 Antworten
+ 18
https://code.sololearn.com/W22Tz6qaZw8p/?ref=app
var input = "javascript is awesome";
var output = "";
for (var x = 0; x < input.length; x++){
if (input[x] === "a") {
output += "4";
}
else if (input[x] === "e") {
output += "3";
}
else if (input[x] === "i") {
output += "1";
}
else if (input[x] === "o") {
output += "0";
}
else if (input[x] === "s") {
output += "5";
}
else {
output += input[x];
}
}
console.log(input);
console.log("");
console.log(output);
+ 11
Sanja Panic always declare variables :)
+ 6
var input = "javascript is awesome";
var arrrpl = {
'a':4, 'e':3, 'i':1, 'o':0, 's':5 };
var output = "";
for (let x = 0;
x < input.length; x++){
if(arrrpl[input[x]]!==undefined)
output += arrrpl[input[x]];
else
output += input[x];
};
console.log(input+"\n"+output);
https://code.sololearn.com/Wdq9ix70FqAJ/?ref=app
+ 6
So i need to add not asign. Thanks r8w9 and Michail Getmanskiy.
+ 6
r8w9 Michail Getmanskiy Do i need to place var or let before variable inside for loop? It work without it but what is correct?
+ 6
Ok, thank you both 😊
+ 5
IMHO: the variable x is a variable need that is only inside the for loop. To limit the scope of its existence and visibility only to the circle, I used 'Let' instead of 'Var'.
+ 1
console.log("javascript is awesome!")
Why doesn't it post as text?