samedi 23 novembre 2019

SyntaxError: expected epression, got keyword 'else'

Could someone help with an error I'm getting in JavaScript?

I'm basically trying to create a login prompt (part of an exercise in a course) with a couple of conditions to match the correct username before the password prompt and then the correct password before alerting 'enter'.

I've tested it in the developer console but I get the above error and no prompts.

I've tried google and have found people have had the same error and I can see where their problem has been in other users' answers but I can't see the same issues in my own code (unless I've just become blind to it!). I feel like it's going to be something really obvious that I'm just not seeing!

Any help would be appreciated!

See code below:

let username = prompt("Username", "Enter Username");
  if(username == "Admin") {
    let password = prompt("Password","Enter Password");
    if(password == "TheMaster") {
      alert("Enter");
    }
  }
  else if(name == "" || name == null) {
    alert("Cancelled");
  }
  else{
    alert("Incorrect username");
  }
  else if(password == "" || password = null) {
    alert("Cancelled")
  }
  else{
    alert("Incorrect password");
  };

Aucun commentaire:

Enregistrer un commentaire