Assessment wanted for Arrays 3 skill tests

Assessment wanted for Arrays 3 skill test(https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Test_your_skills:_Arrays#arrays_3)

let myArray = [ "Ryu", "Ken", "Chun-Li", "Cammy", "Guile", "Sakura", "Sagat", "Juri" ];
let myString = '';

// Add your code here
myArray.pop();

myArray.push('Manish');
myArray.push('Gaurang');

for(let i = 0; i <= myArray.length - 1; i++) {
  myArray[i] = myArray[i] + '(' + i + ')';
  
  if(i != myArray.length - 1) {
   myString += myArray[i] + '-'; 
  } else {
    myString += myArray[i];
  }
}


// Don't edit the code below here!

section.innerHTML = ' ';

let para1 = document.createElement('p');
para1.textContent = myString;

section.appendChild(para1);
    

Hello @Manish_Pamnani and welcome to the community :wave:

Congratulations on this task! It works as intended. :+1:

I just have two simplifications:

  • Instead of i <= myArray.length - 1 you could write i < myArray.length.
  • You could get rid of the if...else statement, by just using myString = myArray.join('-'); after the loop.

I hope that helps. Feel free to ask questions. :slightly_smiling_face:

By the way, for further tasks it would be helpful for us if you could share your code in an online editor like https://codepen.io/ or https://jsfiddle.net/. Thank you :blush:

Have a nice day,
Michael

1 Like