Checking if input is empty? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Checking if input is empty?

How can I check if the input is empty for this code? I usually do something like this: if(number == "") { //Code to execute } But that doesn't seem to work if a space or multiple spaces is present. For example, add that to the code, then input a space and press the button. It returns "is divisible by 2." I'd have to individually add each number of spaces. Is there a way around this? https://code.sololearn.com/W71keXUbAKcL/#html

6th Aug 2018, 10:25 PM
Daniel Cooper
Daniel Cooper - avatar
3 Answers
+ 2
if(number.trim() === "") { //Code to execute }
6th Aug 2018, 10:34 PM
Calviղ
Calviղ - avatar
0
Use number.trim()
6th Aug 2018, 10:31 PM
Calviղ
Calviղ - avatar
0
Can I have an example? I have no idea where to put that xD amnotsmart
6th Aug 2018, 10:32 PM
Daniel Cooper
Daniel Cooper - avatar