samedi 15 octobre 2016

Why won't my code run my IF-ELSE statement correctly?

function checkPIN(pin) {
  if (isNaN(pin)) {
    console.log(pin, ' is not a number');
  } else {
    console.log(pin, ' is a number');
  }  
}

checkPIN(12sf34);

Still quite new to this and cannot for the life of me work out why i can't get a simple check of whether something is a number or not to work?

At the moment i'm getting two errors:

On the above:

Uncaught SyntaxError: missing ) after argument list And on a similar piece of code, it accepts that something is a number and runs my con-log. But when it's NOT a number, it gives an 'undefined' to the letters/not-a-number value.

Can i not use isNaN in a function? Is there a reason why i need an extra bracket/parenthesis somewhere? I cannot for the life of me see a requirement for an extra one.

Aucun commentaire:

Enregistrer un commentaire