Running the function from the prompt


#1

I literally just asked this question, but here is the next part of my code. It won't run the second function (canyon) when I type "east" into the prompt. It will end the code.

Here is what I have:

confirm ("This is a simple text based adventure. Type north, east, south, and west to move. Type capital I to see what your carrying. Everything else should be typed in lowercase. Hit enter to start.")

      cabin()  
        
        
                    //Cabin  
                                             
                
function cabin() {
    var location = 1751;
	console.log("Cabin")
    do {
var location = prompt("You are standing west of the remains of a wooden cabin in an open jungle. The wind is blowing so hard that the trees are almost side ways. There is a wooden door leading into a cave to the north, to the east is a river that looks like it may be traversable, and a barbed wire fence blocks passage to the south.")
    switch(location) {
        
        case 'I':
            console.log("You are carrying a compass.");
            location = 1751;
        break;
        
        case 'west':
            console.log("You can't climb over the cabins debris");
            location = 1751;
        break;
        
        case 'south':
            console.log("You can't climb over the fence it's covered in barbed wire.");
            location = 1751;
        break;
        
        case 'east':
            //canyon
			
            location = 2151;
        break;
        
        case 'north':
            location = 1846;
        break;
        
        default:
            console.log("That isn't a legitimate response.");
            location = 1751;
    }//switch
}//do
        while (location == 1751);
}//function
    
	
	
		
	if(location === 1751) {
		cabin()
	}
	if(location === 2151) {
		canyon()
	}
	if(location === 1846) {
	    cave()
	}
	
	
	
	
	
                    //Canyon
                    
                    
                    
    
	                
function canyon() {
    console.log("Canyon")
    var location = 2151;
    //Default
    do {
var location = prompt("You are standing at the west edge of a canyon. Falling would lead to inevitable demise. You can see about 50 feet out is a massive formation of clouds. There is a river that looks like it may be traversable and what looks like the remains of an old cabin to the west. There is a pathway leading across the edge of the canyon to the north, but the wind is blowing hard and it may not be safe.")
    switch(location) {
        
        case 'I':
            console.log("You are carrying a compass.");
            location = 2151;
        break;
        
        case 'east':
            console.log("You fell off the edge of the cliff. Don't worry, the rocks broke your fall... And your bones... You have died. GG scrub.");
            location = 0;
        break;
        
        case 'north':
            console.log("You fell off the edge of the cliff. Don't worry, the rocks broke your fall... And your bones... You have died. GG scrub.");
            location = 0;
        break;
        
        case 'west':
            //cabin
            location = 1751;
        break;
        
        default:
            console.log("That isn't a legitimate response.");
            location = 2151;
    }//switch
    }//do
    while (location = 2151);
}//function
		
		
			
	if(location === 1751) {
		cabin();
	}
	if(location === 2151) {
		canyon();
	}

#2

Contact a CodeCademy Moderator, and also, repair your code, it is bad organized and difficult to read.


#3

Why do you say that?


#4

I can't answer it by my own, the code is large, and I just know the basics.


#5

Not trying to be rude and I'm sorry if it sounds that way, but why did you reply just to tell me you couldn't help?

Back on the topic though, my code was jumbled up when I posted it and I didn't notice before I left.


#6

Not being rude too, but I just sugested to contact a moderator, and repair your code.


#7

Thank you for the advice.


#9

https://discuss.codecademy.com/t/starting-function-wont-run/35724?u=unexpectedtoken