export function button13_click(event) { $w( “#answer1” ).onCustomValidation( (value, reject) => {
if ( !value === ( “cnut” , “cnute” , “Cnut” , “Canute” )
) {
reject( “Wrong!Try again” );
}
} );
}
I am building an interactive history website at www time safari co uk and one of the applications is an escape dungeon where you have to answer the question “Who was the famous son of Sweyn Forkbeard?” It used to work, then when I added the expand escape button ,expanded with the success message, it stopped.
This is an invalid statement:
if( value!==("cnut","cnute","Cnut","Canute")
Try something like this instead (not tested):
if (['cnut','cnute','Cnut','Canute'].indexOf(value) === 0) {
reject("Wrong! Try again");
}
Some testing can be simplified by only using a lowercase value: value.toLowerCase()
Sorry, it gives everything as the correct answer.
Man, I hate it when I’m stupid (-1 means not found). Try this:
$w.onReady(() => {
$w("#answer1").onCustomValidation((value, reject) => {
if(['cnut', 'cnute', 'Cnut', 'Canute'].indexOf(value) === -1) {
reject("Wrong! Try again");
}
});
});
Note that I set the TextInput’s onCustomValidation() event handler in the page’s onReady(). The event handler is not set in another event handler, such as onClick().
Yep, thank you. When I inputted it a second time -1 came up on the hints. I have moved it to onReady. Well done you! cheers