'My Loop In JS Won't Work For A Mystifying Reason [duplicate]
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
Solution 1:[1]
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 !
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | realexweb |
