samedi 26 juin 2021

Best way to replace empty userinput with 0

I have three userinputs which takes any number. If a user leaves an input empty then clicks the submit button I would like that input to return 0.

What would be the best way to handle this?

I have created an if statement that individually looks for if input 1 or input 2 or input 3 is empty, but what if input 1 and 2 are empty or if input 3 and 1 are empty, this will lead to quite a long if statement

I wanted to know what would be the best way to go about solving this?

*.js

If( hours === 0  ){
hours = 0
}else if ( minutes === 0 ){
minutes = 0
}else if ( seconds === 0 ){
seconds = 0
}
// more if statement with different combination of minutes seconds and hours being 0

Aucun commentaire:

Enregistrer un commentaire