forked from rajeevatlas/JSProblems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepeatString.js
More file actions
38 lines (34 loc) · 788 Bytes
/
repeatString.js
File metadata and controls
38 lines (34 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// function repeatstring(Number, nam) {
// if (Number > -1) {
// if (Number > 0) {
// for (var i = 0; i <= Number; i++) {
// if (Number > 0) {
// console.log("'" + nam + "'");
// }
// }
// }
// else {
// console.log("''")
// }
// }
// else {
// console.log("error");
// }
// }
// repeatstring(0, "pooja");
function repeatstring(nam, number) {
var sum = "";
if (number >= 0) {
for (var i = 0; i < number; i++) {
sum = sum + nam
}
console.log(sum);
}
else {
console.log("ERROR");
}
}
repeatstring("hay", 0);
repeatstring("hay", 1)
repeatstring("hay", -2)
repeatstring("hay", 6)