It's important for you to understand that your Ruby stuff is happening on the server-side and the Javascript is for the client-side. I'm not sure why you would do that in a script. I imagine you could just do that outright in your erb file in Ruby. Note that your Javascript won't know what that means.
Ruby will run, (I'm not sure if Ruby works within the script tags or they purposely don't allow that. I imagine they purposely don't allow that, so that alone will trigger an error), but it won't know what total is. It only understands Ruby. So, when you get to the client-side, you won't have ruby anymore. You'll have the html that was compiled from that Ruby. In your script, you'll have var total = 100; but you won't have that ruby script in there. It'll have been compiled to html. This is assuming erb files even allow that within scripts, which I'm not sure they do.