I'm not a js guy at all... can anyone explain why this doesn't work for the guest challenge? I googled a bit and it seems like it should have.
function guestChallenge() {
// code goes here
var num = 0;
for (var i = 1; i< 1001; i++) {
if (i.toSring(10).match(/7/));
else num+=i;
}
return num;
}
Edit: I really should have added more context! The challenge was:
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.
And my program didn't generate any output at all, which leads me to believe I made a syntax error as opposed to just a logic error.
Edit again: Yes. I just had to fix my typing error ("toSring"), and then it passed. Thanks, guys!
To others, the demo question on the home page is a divisible by 5 or 7 problem. This is one of the guest challenges and is that the number contains the digit '7'.
Thank you... I can't believe I wasn't seeing that!
I'm surely not the only one to do this sort of thing. Maybe there should be some kind of feedback instead of nothing happening when I click the run button.
You are thinking of the challenge on the front page. He's talking about the first of the three "guest challenges" you get if you click the link on the front page to see more challenges.
The front page challenges asked for the sum of the integers from 1 to 1000, excluding those divisible by 5 or 7. Here was my sort of smart-ass answer:
function jsChallenge() {
var num = 1000;
var t = num;
var sum = t*(t+1)/2;
t = Math.floor(num/5);
sum -= 5*t*(t+1)/2;
t = Math.floor(num/7);
sum -= 7*t*(t+1)/2;
t = Math.floor(num/35);
sum += 35*t*(t+1)/2;
return sum;
}
The first guest challenge asks for the sum of the integers from 1 to 1000, excluding those that contain the digit 7.
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.
And my program didn't generate any output at all, which leads me to believe I made a syntax error as opposed to just a logic error.
Edit again: Yes. I just had to fix my typing error ("toSring"), and then it passed. Thanks, guys!