Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c365b06

Browse files
author
Jimmy John
committed
guest challenge1
1 parent 4065f87 commit c365b06

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

guest-challenge1.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Using the JavaScript language, have the function guestChallenge() add up all of the numbers from 1 to 1000. But everytime a number that contains a 7 is reached, don't add that number to the others (ie. exclude 7, 17, 370, etc). Do not put any code outside of the function and use the return keyword to return your answer from within the function.
3+
*/
4+
5+
function guestChallenge() {
6+
7+
var i = 0;
8+
var sum = 0;
9+
10+
while (i < 1001) {
11+
if (i.toString().indexOf('7') == -1) {
12+
sum += i;
13+
}
14+
i++;
15+
}
16+
17+
return sum;
18+
19+
}
20+

0 commit comments

Comments
 (0)