samedi 22 août 2020

Issues with simple task: Conditional statements in JavaScript

I'm doing a school task with conditional statements. I'm trying to code something that asks for the amount of pets the user has and then combine the answers, which will return a value/answer depending on the earlier given values.

const dogs = prompt('How many dogs do you have?');
dogs = parseInt(dogs);

const cats = prompt('How many cats do you have?');
cats = parseInt(cats);

const otherPets = prompt('How many other pets do you have?');
otherPets = parseInt(otherPets);

const totalPets = 'dogs' + 'cats' + 'otherPets';

if (totalPets > 0){

alert('You have a total of 'totalPets'pets.');
}

else{

alert('You should probably get yourself a sloth.');
}

Aucun commentaire:

Enregistrer un commentaire