mardi 17 août 2021

"if" with "Or" and "AND" and must be a "number" doesn't work [closed]

I'm learning JS and I don't understand why:

1- The if says that I can't pay when I'm telling that If cash or credit or available is greater or equal than totalAmount. When available is greater indeed. I noticed that if I type cash+credit it works, but I'd like to make it with or.

const cash = 300;
const credit = 400;
const available = cash + credit;
const totalAmount = 600;

if ((cash || credit || available) >= totalAmount && 
typeof cash === 'number' && typeof credit === 'number') {
    console.log('You can pay')
} else if(typeof (cash,credit, totalAmount) !== 'number' ){
    console.log('Don\'t be a pirate')
} else{
    console.log('You\'re poor');
};

2- I don't know how to write the "else if" to differentiate the number from strings with (), for example:

    else if(typeof (cash,credit, totalAmount) !== 'number' ){blablabla}

3- Silly question: The code looks messy, How do you order the code from "long" lines of the same sentence?

Aucun commentaire:

Enregistrer un commentaire