hello everyone please i'am a begginer in javascript and i found this challenge , but i don't know how to solve it
let str1 = "javascript";
// Example output:
// jZvZsZrZpZ OR each letter on a new line
// HINT: You can use if((i+1) % 2 == 0) to check for even indexes
for (let i = 0; i < str1.length; i++) {
if ((i + 1) % 2 === 0) {
str1[i].replace(str1[i],"z")
}
}
can you explain this for me please i try this soltuion but it doesn't work
let str1 = "javascript";
// Example output:
// jZvZsZrZpZ OR each letter on a new line
var a = str1.split("");
let replaceChar = function(char){
for(let i=1;i<str1.length;i++){
if((i+1)% 2 === 0)
a[i] = char
}
return a.join("");
}
console.log( replaceChar("Z"))