-1

Ive been studing JS for 2 month and my teacher gave this assignment so as usuall i solve it but here i tried many hours but i can't Although that i'm pretty sure my answer logically is right but i don't know why the name repeated just one time

The Required Output is :

String [Osama], [Mohamed], [Ali], [Ibrahim] => Done !

Important Note : The [] isn't an array

/*
  Function Arrow Challenges
*/

// [1] One Statement In Function
// [2] Convert To Arrow Function
// [3] Print The Output [Arguments May Change]

let names = function (...name) {
  for (let i = 0; i < name.length; i++) {
    return `String [${name[i]}], => Done ~`
}};

console.log(names("Osama", "Mohamed", "Ali", "Ibrahim"));
// String [Osama], [Mohamed], [Ali], [Ibrahim] => Done !

Question : How could i solve this ? with a logical explain to the answer

MrKing09
  • 41
  • 7

1 Answers1

-2

try to add String [${name[i]}], => Done ~ into variable , for example

var S+=`String [${name[i]}], => Done ~`
return S;

/*
  Function Arrow Challenges
*/

// [1] One Statement In Function
// [2] Convert To Arrow Function
// [3] Print The Output [Arguments May Change]

let names = function (...name) {
  for (let i = 0; i < name.length; i++) {
    return `String [${name[i]}], => Done ~`
}};

console.log(names("Osama", "Mohamed", "Ali", "Ibrahim"));
// String [Osama], [Mohamed], [Ali], [Ibrahim] => Done !
realexweb
  • 35
  • 2