Show or Hide image on dynamic page based on the current item's value in number field

I have a dynamic page set up to show information about individual items in a collection. I want to be able to hide/unhide a star element based on the rarity of the current item, and the rarity is stored as a number value in the database. I want the image (endStar) to hide if the current item’s number value in the rarity field is 4. This is the code I have currently.

$w.onReady(function () {

$w("#dynamicDataset").onReady(() => {
 const item = $w("#dynamicDataset").getCurrentItem();
 if (item.rarity==="4") {
            $w("#endStar").hide();
        }
    });
});

});

I am not sure what part of this is causing it to not work. I’m very new to coding, so I’m just looking for the easiest way to achieve this.

It depends on how you configured your database.
Or even more precise, how you defined the related DB-FIELD.

Is it a …
a) NUMBER-FIELD ???
b) TEXT-FIELD ???

Try this one instead, if your DB-FIELD was configured as → NUMBER!

$w.onReady(function(){
	$w("#dynamicDataset").onReady(()=>{
		let item=$w("#dynamicDataset").getCurrentItem(); console.log(item);
		if(item.rarity===4){$w("#endStar").hide();}});
		else {console.log("Do something else here!");}
	});
});

Also use some console-logs, to inspect your own code and to show results in your console.

Thank you! It was defined as a number field. I did a little tweaking and managed to get it to work.