Skip to content

Week3 #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
homeowrk3
  • Loading branch information
Nouransaeed committed Aug 14, 2019
commit 58d7c4ae125ce33ddfcad57f2b03f6b187018172
60 changes: 40 additions & 20 deletions Week3/homework/step2-3.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,67 @@
'use strict';

// Use a 'for' loop
function repeatStringNumTimesWithFor(str, num) {
// eslint-disable-next-line prefer-const
let result = '';
for (let i = 0; i < num; i++) {
result += str;
}
return result;

console.log('for', repeatStringNumTimesWithFor('abc', 3)),

// Replace this comment and the next line with your code
console.log(str, num, result);

return result;
}

console.log('for', repeatStringNumTimesWithFor('abc', 3));
//while loop

// 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);
let result = '';

let counter = 0;

while (counter < num) {

result += str;

counter++;

}

return result;
}

}
console.log('while', repeatStringNumTimesWithWhile('abc', 3));
// 'do...while' loop

// Use a 'do...while' loop
function repeatStringNumTimesWithDoWhile(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);
let i = 0;

if (num > 0) {

do {

result += str,

i++;

} while (i < num);

}

return result;
}
console.log('do-while', repeatStringNumTimesWithDoWhile('abc', 0)),

console.log('do-while', repeatStringNumTimesWithDoWhile('abc', 3));

// Do not change or remove anything below this line
module.exports = {

repeatStringNumTimesWithFor,

repeatStringNumTimesWithWhile,

repeatStringNumTimesWithDoWhile,

};


pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy