One of my students is having trouble with their code, which Is not working. Is anyone able to help figure this out? Whenever any option is clicked, it results in an undefined in the output textbox for them. I have pasted their code below for anyone to see.
//Variables Used In Program
var name;
var price;
var height;
var sport;
//main code
onEvent(“nameField”, “input”, function( ) {
name = getText(“nameField”);
updateScreen();
setText(“output”, "Hey " + name + ". " + "The sport that is recommended that you should play is " + sport + “!”);
console.log(“Code Works”);
});
onEvent(“priceDropdown”, “input”, function( ) {
price = getText(“priceDropdown”);
updateScreen();
setText(“output”, "Hey " + name + ". " + "The sport that is recommended that you should play is " + sport + “!”);
console.log(“Code Works”);
});
onEvent(“heightDropdown”, “input”, function( ) {
height = getText(“heightDropdown”);
updateScreen();
setText(“output”, "Hey " + name + "! " + "The sport that is recommended that you should play is " + sport + “!”);
console.log(“Code Works”);
});
//Update Screen Function
function updateScreen() {
if (height == “<5ft”) {
sport = “Soccer”;
} else if (price == “$” && height == “>=5ft”) {
sport = “Basketball”;
} else if (price == “$” && height == “>=6ft”) {
sport = “Basketball”;
} else if (price == “$” && height == “>=7ft”) {
sport = “Basketball”;
} else if (price == “$$” && height == “>=5ft”) {
sport = “Soccer”;
} else if (price == “$$” && height == “>=6ft”) {
sport = “Soccer”;
} else if (price == “$$” && height == “>=7ft”) {
sport = “Basketball”;
} else if (price == “$$$” && height == “>=5ft”) {
sport = “Tennis”;
} else if (price == “$$$” && height == “>=6ft”) {
sport = “Football”;
} else if (price == “$$$” && height == “>=7ft”) {
sport = “Basketball”;
} else if (price == “$$$$” && height == “>=5ft”) {
sport = “Tennis”;
} else if (price == “$$$$” && height == “>=6ft”) {
sport = “Tennis”;
} else if (price == “$$$$” && height == “>7ft”) {
sport = “Tennis”;
}
}