For some reason that is beyond me, the pricing is not showing correctly in this decision maker app. Please advise. It is from Unit 4 Lesson 12 and I want to help him figure it out. Thank you in advance.
hello @darrin.patterson
// Variables
var food;
var drink;
var dessert;
var price;
//Code to get to Order Screen
setScreen("mainScreen");
onEvent("mainscreenButton1", "click", function () {
playSound("sound://category_achievements/lighthearted_bonus_objective_4.mp3", false);
setScreen("selectfoodScreen");
});
// Button to EndScreen
onEvent("submitfoodButton", "click", function () {
food = getText("foodDropdown");
drink = getText("drinkDropdown");
dessert = getText("dessertDropdown");
price = 18;
// Main Code
if (food == "Pizza" && (drink == "Water" && dessert == "Brownie")) {
price = price - 3;
} else if ((food == "Salad" && (drink == "Sweet Tea" && dessert == "Cake"))) {
price = price - 4;
}
playSound("sound://category_achievements/lighthearted_bonus_objective_4.mp3", false);
updateScreen();
});
//Update Screen Function
function updateScreen() {
setScreen("submissionEndScreen");
setProperty("totalpriceLabel", "text", "\nPrice: $ " + price);
console.log("Thank You For Your Purchase!!!");
}
you should really learn how events work i’ll bullet the main issues
- undefined cannot be subtracted from
- getText values do not update the variables unless called by an event or loop
- main code is not tied to the submit order button
Thank you for the insight. I take it that you have either been teaching this for a while or are used to working in JavaScript. I am new at this and am not yet at the level where I can solve all of my student’s issues. So, I appreciate all the help that I receive.
Well, thanks to varrience, I have seen the errors that were made and sent my student a corrected version of his app. Thank you again.