Then you should be creating a HTML file rather than JS
Where did you get this code from…
If I’m not wrong this is what you want…
<!DOCTYPE html>
<html>
<head>
<title>Bolt IoT Platform</title>
<script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js"></script>
<script>
setKey('{{ApiKey}}','{{Name}}');
</script>
</head>
<body>
<center>
<button onclick="analogWrite(0, 20);">ON</button>
<button onclick="analogWrite(0, 160);">OFF</button>
</center>
</body>
</html>
LED Brigthness ranges from 0 to 255
If you wish to add a slider that would toggle the brightness.
Check this out