These are chat archives for codefellows/sea-f1-TAs/Brian

Sep 2014
Ryan Christensen
Sep 07 2014 03:45
var guess, sandyWeight, eggWeight;
eggWeight= Math.floor(Math.random() 2);
sandyWeight = Math.floor(Math.random()
13) +1;
for (i = 1; i < 3;i++ ){
guess = prompt("How many eggs are required for an egg sandy that weighs " +sandyWeight+ " pounds?");

if (guess > eggWeight) {
message = "To many, think less!";
else if (guess == eggWeight) {
message = "Perfect!"
else if (guess < eggWeight) {
message = "Not enough yummy eggs..."
} else {
message = "Guess again..."


Oops, forgot to ask my question... I have this for loop in the wrong place/am giving it the wrong instructions. I want the if/else if/else statement to repeat if the guess != eggWeight. It keeps looping the prompt.
Linda Mummy
Sep 07 2014 03:55
A for loop is going to run the code inside it a set number of times (in this case, 2 time, for i=1 and i=2). If you want your program to keep asking for a guess until the user guesses correctly you could use a while loop (while (guess != eggWeight))
Brian Caldwell
Sep 07 2014 03:56
Linda has it right. Use For loops when you know how many times you want it to run, use While loops when you don't know how many times it should run
Ryan Christensen
Sep 07 2014 05:51
Thanks again!