lundi 1 février 2016

How to reference a previous prompt() in JavaScript?

I want to ask a user (through a prompt) if they would rather convert km to miles, or miles to km, within an else if statement. If neither condition is met, I want to go back to the conversion prompt:

var conversion=prompt("Do you want to convert miles to km, or km to miles?");
if (conversion=="miles to km") {
[perform miles conversion here]
} else if (conversion=="km to miles") {
[perform km conversion here]
} else {
**[go back to conversion prompt]**
}

How would you code this line in JavaScript? Thanks.

Aucun commentaire:

Enregistrer un commentaire