11/11


#1

this is my code:

// Write your code below!
var text= function(Tyler){
for (var i=0; i<text.length; i++) {
    console.log(text(i));
}
};
console.log(text);


for (var fives = 5; fives < 26; fives += 5;) {
    console.log(fives);
}

var print = true;
while(print) {
    console.log("This is the second loop.");
print = false;

}

var printTwo = false;

do {
    console.log("This is ");
    console.log(printTwo);
    printTwo = false
}

while printTwo = true

but it says there is an unexpected token, can someone help?


#2

Look closely here...


#3

should I remove the i before the console.log?


#4

Well, the way you're supposed to use a for loop is like this:

The structure:

for(var _ = _; __ (put comparator here) __; (put variable) (put how the variable is going to go)){}

Example:

for(var i = 0; i < 25; i++){
console.log(i);
}

This code will print all number from 0 or 1 to 24, I believe.


#5

Im too confused because

var text= function(Tyler){
for (var i=0; i console.log(text(i));

I think its this


#6

What are you trying to do? Please explain.


#7

What I'm trying to do is that the instructions say to type a while, for, and a do loop, I did them correctly, but it says : unexpected token


#8

First of all, why don't you take out this:

Because you don't need a function.

Second, you accidentally put a second while here:

You should replace while with var. Also, take out the printTwo= false in your do loop, for it is already false. AND, with you while loop:

Why don't you replace

with printTwo.

It may or may not work with these corrections, but try them out!:smiley:


#9

nope, still didnt work :confused:


#11

your code has many many syntax error.. i tired very hard to fix it as following:

var text = function(Tyler) {
var Tylerr = Tyler;
alert(Tylerr.length)
for(var i=0;i

        alert(Tylerr[i]);
    }

    for (var fives = 5; fives < 26; fives += 5) {
        console.log(fives);
    }

    var print = true;
    while (print) {
        console.log("This is the second loop.");
        print = false;

    }

}
text("hahahahha");

and its not right to use Do While like that .


#12


#13

oh.....lets just say I really suck at looping XD how could I get more practice on them?


#14

Write your name 10000 times perhaps it makes you think isn’t there a better way to do this :smile:
No really think of repeating and stuff and try to write it as a loop. Also when you want to practice it better use labs repl.it instead of a random exercise.


#15

Speaking of labs, Im making a game using js :smiley: but, When I open the download, it wont let me edit it, can someone help me? I think I could use looping in the game but dont know how


#16

Sure you can use loops in game escpacially if it is about graphis whole animations are in the end just loops. Where do you download what and why doesn't it open?

PS: Also have you seen this post:


#17

I just download the file and when I open it, it wont let me edit


#18

What file did you download from which side and with which content and with what did you try to edit it?


#19

It’s called survivial_game.mhtml. thats it. theres really nothing special about it.

Code

console.log("The year is 3021. You are part of an elite fireteam of the 543rd Red Wings. You were on a special tactics mission and was overrun by the enemy. You managed to take an escape pod but unfortunately crashed on an unknown planet inhabited by foreign organisms. All you have is your S.T.R droid to help you survive.");

var playerName=prompt("Do you remeber your name? What is it?");

    console.log("Hello" + " " + playerName);
    
        var playerAlive="Your bloodpressure is stable and your heart rate is at 63 beats per minute.";
        
            console.log(playerAlive);
            
                var playerChoice = prompt("Would you like to go to the forest, the mines, or the wilderness?");
                    
                    if (playerChoice === "forest") 
                    {
                        console.log("You head to the forest.");
                    }
                
                        else if (playerChoice === "mines") 
                        {
                            console.log("You go to the mines");
                        }
                        
                            else 
                            {
                                console.log("You venture into the wilderness");
                            }
                            
                              var monsterOutput = Math.random();
                              
                                console.log(Math.random());
                                
                                    if (monsterOutput <= .33)
                                    {
                                        console.log("You found nothing useful.");
                                    }
                                    
                                    else if (monsterOutput <=.34)
                                    {
                                        console.log("You are too scared so you head back");
                                    }
                                    
                                    else  
                                    {
                                        console.log("A monster attacks you!");
                                    }
                                    
                                    var playerChoice2 = prompt ("What do you want to do?");
                                    
                                    if (playerChoice2 === "head back") 
                                    {
                                        console.log("You head back to your safehaven");
                                    }
                                    
                                    else if (playerChoice2 === "kill the monster")
                                    {
                                        console.log("You have killed the monster! After the frightening moment of battling an unkown creature, you decide to head back to the safehaven to rest for the next day.")
                                    }
                                    
                               //second time the player is prompted about where to go. maybe loop here? Ask cow!!!     
                                    
                                        var playerChoice = prompt("Would you like to go to the forest, the mines, or the wilderness?");
                    
                    if (playerChoice === "forest") 
                    {
                        console.log("You head to the forest.");
                    }
                
                        else if (playerChoice === "mines") 
                        {
                            console.log("You go to the mines");
                        }
                        
                            else 
                            {
                                console.log("You venture into the wilderness");
                            }
                
                                    

#20

It's not really a download but more like a share the link button and I can edit it.


#21

edit it to what? because I wanted it to put it on my google site. :smile: