Jquery "if" function

Hello! I am trying to set an if function for Jquery, but it is not working. I wanted to know if the editor supported if functions, as when I remove them the function works.

Thanks!

<script>
 const emailamount = $('.cms-email-counter').length;
 
 $('.email-counter').text(emailamount);

 let postNumber = 1;

if (postNumber >= 2) {
	$('#back').on('click', function(){
		postNumber = postNumber-1;
		console.log(postNumber);
		$('#email-number').text(postNumber);
});
};

if (postNumber <= emailamount) {
	$('#next').on('click', function() {
  	postNumber = postNumber+1;
  	console.log(postNumber);
    console.log(emailamount);
    $('#email-number').text(postNumber);
});
};

console.log(postNumber);



$('#email-number').text(postNumber);

</script>

Hi @Julieta_Newland,
Welcome to the forum. It would be helpful if you follow the guidelines for posting to this category. Sharing a link to a published page where you are running this code is really essential to debugging.

The designer supports running custom code and any JS just needs to be correct. You can debug code in your browser and that is the best place to start.

Hi Jeff!

Oh, yes. Here is the link to the page: Sign up for the Bueno newsletter .

I’ve tried looking in the console for errors everything seems to be working fine.

Thank you!

Hi @webdev I wondered if you had a chance to look at the project, thanks!

Sorry no. If you want coding help you could always submit a freelance request or wait. I am booked to the gills right now.

No problem! Thank you!