What you need to do is change the file extension of the included script to .php from .js. Your new code should look like this:
<?php $amount = 42; ?> var myvar = <?php echo json_encode($amount); ?>;
I hope this tutorial helped you! If you have any questions, make sure to leave them in the comments.
Thanks for reading!