Hi. I’m trying to write a sports prediction site whereby players can predict scorelines and then be awarded points if they’re correct. I’ve set up a predictions form that feeds into a database and I have another column in the database called results. I want to get this field to display the word ‘home’ or ‘away’ depending on the scoreline. Here’s the code I’ve done so far - I’ve included comments on what I’m trying to achieve with each line of cod.
import wixData from ‘wix-data’;
var game1_h, game1_a; //define the 2 scoreline fields
var game1_result = [“home”, “away”]; //define the 2 possible answers for the results field
wixData.query(“Week1_Preductions2”)
.contains(“game1_h”, 0)
.contains(“game1_a”, 1)
.find() //search the Week1_Prediction2 database for the values in fields ‘game1_home’ and ‘game1_away’
.then( (results) => {
if (game1_h >= game1_a) {
$w("game1_result").value = results["home"]; //inserts the word ‘home’ in the results field if the home team wins or draws
}
else {
$w("game1_result").value = results("away"); //inserts the word ‘away’ in the results field if the away team wins
}
} );
console.log(game1_result);
Can anyone please help and show me where I’m going wrong?
Thanks a lot,
Paddy