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

147
Views
My Loop In JS Won't Work For A Mystifying Reason

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

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

0

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 !

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!