Answer input - AppLab

applab
#1

My class are currently using AppLab to create a range of different apps and one of them is trying to use a text input button for a user to type in an answer for the app to then change screens to show whether the answer is correct or not. He has worked out how to insert a text input box, but how would he build the code to assess the answer as correct or incorrect? Thanks in advance!

Here’s the link to his project: https://studio.code.org/projects/applab/GtGj8C53EzwTNUeCNDc0ONThrVBKHqQL2KVitKdrbSM/view

#2

I was unable to access the code. It does not have share permissions. But the student would need a “change” event for the textbox. Get the text typed in by the user by using getText and then compare the text to the answer using “==”. Here is an example:

onEvent(“user_guess”, “change”, function(event) {
//get user input and convert to lowercase
var currentGuess = getText(“user_guess”).toLowerCase();

//Display error message if blank entered or nothing entered
if (currentGuess == " " || currentGuess == “”){
showElement(“blankErrorLabel”);
setText(“user_guess”, “”);
}
else {
if (currentGuess == value)
setScreen(“winScreen”);
else
setScreen(“loseScreen”);
}
});