1

This is a two part question, I currently have the below code and I'm trying to have it so that the console will tell me if it is a lower case letter or an upper case letter or of it is a number. I cant seem to get the number.isInteger to work so please tell me where I am going wrong with that.

Also I would like to have it so that there is a call back of what the user entered. So instead of it just saying "This is a upper case letter" I would like it to state "The letter g you entered is lowercase" and vice versa for upperCase and numbers.

Hope that makes sense, please find below my current code. I am new to coding and javascript so please try dumb it down as much as possible for me. Thanks!

Please see below code I currently have:

    let upperLower = prompt("please enter either a uppercase letter, lowercase letter or a number");

if (upperLower == upperLower.toLowerCase()) {

  console.log("The character is lowercase");
}
else if (upperLower == upperLower.toUpperCase()) {
    
    console.log("The character is uppercase");
}
else if (upperLower == Number.isInteger()){

    console.log("This is a number");
}
Nikola Pavicevic
  • 21,952
  • 9
  • 25
  • 46
PoisonMaster
  • 27
  • 1
  • 6
  • Does this answer your question? [How to check if a variable is an integer in JavaScript?](https://stackoverflow.com/questions/14636536/how-to-check-if-a-variable-is-an-integer-in-javascript) – Tushar Shahi Jul 15 '21 at 19:35

1 Answers1

0

Or you can check if input converted to number is not a number (isNaN) is false

let upperLower = prompt("please enter either a uppercase letter, lowercase letter or a number");
if (!isNaN(parseInt(upperLower))){

    console.log(upperLower + " is a number");
}
else if (upperLower == upperLower.toLowerCase()) {

  console.log(upperLower + " character is lowercase");
}
else if (upperLower == upperLower.toUpperCase()) {
    
    console.log(upperLower + " character is uppercase");
}
Nikola Pavicevic
  • 21,952
  • 9
  • 25
  • 46
  • Thanks so much for this, very interesting to see how you have done it. could you explain what isNan and parseInt is for me please ? also is there a way to print out and recall what letter/number the user entered ? E.g if they enter the number 1 the console will say "1 this is a number" – PoisonMaster Jul 15 '21 at 19:48
  • sure mate , The [isNaN()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN) function determines whether a value is NaN (not a number) or not. The [parseInt()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt) function parses a string argument and returns an integer – Nikola Pavicevic Jul 15 '21 at 19:55
  • Thank you! appreciate the help! – PoisonMaster Jul 15 '21 at 19:58