Python-code that does not translate to JavaScript properly will result in JavaScript-code that will not run. So you need to make your Python-code JavaScript compatible. Check the crib sheet by @wakecarter.
Best wishes Jens
BTW. please surround code with triple `. This result in proper formating.