Don't know that it expecting. And "else" problem again


#1


https://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/4?curriculum_id=506324b3a7dffd00020bf661


SyntaxError: expected expression, got keyword 'else'
Started out to make something small, but it got out of hand.


var user = prompt("Where would you like to go, LIBRARY, PARK or RIVER?").toUpperCase();
    switch(user){
        case 'LIBRARY':
            console.log("It's quiet and cool in here. \ You look around.");
            var whatTo = prompt("What are you here for, for some book: YES or NO?").toUpperCase();
                if (whatTo === 'YES')    {
                    console.log("The book you came for is on the shelf. \ You checkout it and back home. \ You put the book on the desk. \ The book remains there all the week, untouched.")}
                              
                    if (whatTo === "No") {
                    console.log("You stroll arould, find a interesting book title \ and read the first chapter.");
                   var wow = prompt("Was the book interesting: YES or NO?").toUpperCase();
                     if (wow === 'YES'){ 
                         console.log(" Fascinating book! \ You forgot time and read on. \ What a great day!")}
                                
                     if (wow ==='No') {
                         console.log("You return the book to its place, and turn to see another book. \ Then you saw a little card on the floor.")
}
                    var card = prompt("Do you pick the card up: YES or NO?").toUpperCase();
                      if (card === 'YES') {
                       console.log("You pick up the card. A poem is written on it. \ You read it and like it. Seems it is from somebody's notebook. \ You go to the librarian's desk and ask about the poem. \ She checks it and gives you the title and the name of the poet. \ One of the poetry book is available. \ You decide to check it out. \ You feel very happy.")}
                        
                      else {
    console.log("Looks like somebody's memo. \ You leave it there and go home. \ Another lazy day...")}
            
              break;
            }break;
 
I removed my original horrible script and here copied the first part of my corrected one.


#2

this line:

if (hotdog == 'BUY'){ 
        console.log("You bought a hotdog and happily eating it, \ then something dark flew by \ and your hotdog is gone. \ A big crow! \ It lit on the nearby tree and ate your hotdog. \ Disgusted, you goes back to home.")}
        break;

break should be before the }, else if has to be after a if or another else if. There might be more syntax problems, try a more verbose editor like jsbin


#3

Thank you, I visited that site an saw what it says. Couldn't understand. I use Firebug on Firefox. That one catches an error and points it out. Not that I understand what it is trying to say.


#4

You shouldn't ever be working with code formatted that way, that's probably the biggest reason you have the problem and also why you couldn't find it. Fix it before you do anything else! I'd run it through a program to re-format it, but it may also be worth the practice to do it yourself.


#5

After days of headache, visited JSHint. The program pointed out errors, with line numbers. I corrected as much as I could and, wow!! passed. Thank you, I'd be careful about the format. It seems every time I copy/paste my script from my editor to another programs like scratch pad or the editor on this site, the tabs and format somewhat changed. Or is that my eyes?


#6

Dunno? Depends on your clipboard application and what you're pasting into. Most programs won't behave like that. You could compare them. If that's really the case then it may be good to be aware of it. Maybe you're using a font with varying character width? Maybe you have actual tab characters (as opposed to spaces) and different programs display them with different widths?


#7

I do not use tabs for spacing, so it can be fonts. I'll check that, thank you.


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.