Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
change even character in string with the for loop

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

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This should work for you. JsFidle

let str1 = "javascript";  

const res = [...str1].map((letter, index)=>{
 return index % 2 != 0 ? "Z" : letter
})

console.log(res.join(""))
about 4 years ago · Juan Pablo Isaza Report

0

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"))

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!