Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
step 2-3 done!
  • Loading branch information
EliaYazdi committed Aug 2, 2019
commit 5e7684cf61e432c991e3d61a4efb3ca7893e1d8d
23 changes: 16 additions & 7 deletions Week3/homework/step2-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@ function repeatStringNumTimesWithFor(str, num) {
// eslint-disable-next-line prefer-const
let result = '';

// Replace this comment and the next line with your code
console.log(str, num, result);
for (let i = 0; i < num; i++) {
result = +str;
num--;
}

return result;
}

// but when I console.log it returns : for NaN!!!!
console.log('for', repeatStringNumTimesWithFor('abc', 3));

/*************************************************************************/

// Use a 'while' loop
function repeatStringNumTimesWithWhile(str, num) {
// eslint-disable-next-line prefer-const
let result = '';

// Replace this comment and the next line with your code
console.log(str, num, result);
while (num > 0) {
result += str;
num--;
}

return result;
}
Expand All @@ -30,9 +36,12 @@ console.log('while', repeatStringNumTimesWithWhile('abc', 3));
function repeatStringNumTimesWithDoWhile(str, num) {
// eslint-disable-next-line prefer-const
let result = '';
let i = 0;

// Replace this comment and the next line with your code
console.log(str, num, result);
do {
result = +str;
i++;
} while (i < num);

return result;
}
Expand Down