11. Review help


#1



Hey guys, I'm finally up to the Review chapter, and I tried to be just a tad bit fancy. The error message I'm getting is "SyntaxError: missing ) after argument list" Mind helping me out? Thanks!


for (i = 0; i < 30; i++) {
    console.log("You flipped your coin " i "time(s)");
}

var hit = Math.random
while(hit <= 0.30) {
    console.log("You nailed it!");
}

no = 0
do {
    console.log("This isn't real, is it...");
} while (no = 1);


#2

this won't work:

console.log("You flipped your coin " i "time(s)");

you need to concate the string:

console.log("You flipped your coin " + i + "time(s)");

and Math.random() also seem to miss some brackets


#3

Okay, so here is my new code

for (i = 0; i < 30; i++) {
console.log("You flipped your coin " + i + "time(s)");
}

var hit = Math.random()
while(hit <= 0.30) {
console.log("You nailed it!");
hit = 1
}

no = 0
do {
console.log("This isn't real, is it...");
} while (no = 1);

But for some reason, it takes me on an infinite loop now. What's up with that?


#4

please take a look at my answer here, which is wrote a minute ago. you are not comparing no with 1, you are assigning 1 to no, 1 is considered true, causing a infinity loop


#5

Ah, thanks alot Stetim!


#6

Just one last thing, the code runs fine, but the text for my while loop isn't logging. Do you know what the issue is there?


#7

well, it only logs if hit is smaller or equal then 0.3, which is in a lesser change then 1 in three. If you run it several times, i am sure it will log at some point


#8

Thanks, I figured that was the case. Just had to make sure. You've been a big help