Skip to content

Instantly share code, notes, and snippets.

@Ross-Hunter
Created October 19, 2017 20:42
Show Gist options
  • Save Ross-Hunter/938d314838fa7868a6b02575c29534df to your computer and use it in GitHub Desktop.
Save Ross-Hunter/938d314838fa7868a6b02575c29534df to your computer and use it in GitHub Desktop.
// ** Mad Libs **
// Ask the user for the words to fill in the blanks
var who = prompt("a person");
var what = prompt("a thing");
var amount = prompt("a number");
// prompt always returns a string. here we convert it to a number
amount = Number(amount);
// calculate the total
var total = amount * 5;
// concatenate all the parts together using +
console.log(who + " went downtown and bought some " + what + ". They bought " + amount + ", paying $" + total + ".");
// Ticket Vend
var adultTicketsCount = Number( prompt("How many adult tickets?") );
var childTicketsCount = Number( prompt("How many child tickets?") );
var totalPrice = adultTicketsCount * 10 + childTicketsCount * 5;
var totalTicketsCount = adultTicketsCount + childTicketsCount;
if (totalTicketsCount >= 12) {
totalPrice = totalPrice - (.20 * totalPrice);
}
var memberYesOrNo = prompt("Are you a member? Type 'yes' or 'no'.");
if (memberYesOrNo === "yes") {
totalPrice = totalPrice * .9;
} else {
console.log("You can get a 10% discount if you join our membership program.");
}
console.log("Total: $" + totalPrice);
// Ticket Vend 2
var totalPrice = 0;
var totalTicketsCount = 0;
var choice;
do {
choice = prompt("Which ticket? (adult, child, or done)");
if (choice === "adult") {
totalTicketsCount++;
totalPrice += 10;
} else if (choice === "child") {
totalTicketsCount++;
totalPrice += 5;
}
} while (choice !== "done");
if (totalTicketsCount >= 12) {
totalPrice = totalPrice - (.20 * totalPrice);
}
console.log("Total: $" + totalPrice);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment