How can I get a greater than function code to work?

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

Hi Paddy,

Your code has many Wix Code and Javascript errors. I would recommend starting with Wix Code Basics . You can also play with some of the Wix Code Examples which will let you learn by observing working apps. The tutorial How to Use Code to Let Your Users Search a Collection demonstrates how to perform queries and other database techniques.

A gentle warning: The system you are describing is not trivial and will be a challenge for beginner coders. As you learn, we’ll be here to help you get pointed in the right direction.

If your project is urgent and you won’t have enough time to learn how to build your app, you might want to consider checking out the WixArena - it’s a hub where you can look for Wix Code (and other) experts for hire.

Have fun and good luck,

Yisrael

Thanks for that Yisrael. I appreciate the feedback.
Paddy