Quote:
Originally Posted by SolidSamurai
It wouldn't be client side.
|
If it's JavaScript, it's clientside. Simply because JavaScript runs on the client/browser.
JavaScript Code:
<html>
<head>
<script language="javascript">
combatplayerattack=new Array();
combatplayerattack[0]="You barely catch ' + monster + ' with your ' + playerweapon + '";
combatplayerattack[1]="You ' + playerweapon + ' plunges deep into ' + monster + '! Critical Hit! ";
combatplayerattack[2]="You swing your ' + playerweapon + ', but ' + monster + ' skimly avoids!";
combatplayerattack[3]="Your weapon is deflected!";
combatplayerattack[4]="Your attack misses completely!";
combatplayerattack[5]="From the reaction of ' + monster + ', it's clear that your ' + playerweapon + ' hurt it somewhat!";
var randomplayerattack = combatplayerattack[Math.floor(Math.random() * combatplayerattack.length)]
</script>
<button onclick="document.write(' + randomplayerattack + ')">Attack</button>
</head>
<body>
</body>
Other than the obvious missing variable declarations you mentioned, you have the quotes wrong almost everywhere.
To insert the value of a variable in a string, you must split it to two strings:
JavaScript Code:
myVar = "string one, " + myOtherVar + ", string two";
Add two doublequotes here as well:
Using document write there isn't much point as you can only do it while the page loads, but I'm assuming you already knew that and used this as a testcase.
Edit: I just noticed the <button> tag was in the <head> tag too, where it won't be rendered as only stuff in <body> normally is.
End User has a point, tho be it a bit hidden. Always check the syntax, preferably after each new line. The problems you had here are easy to spot with a highlighting editor like say tsWebEditor or UltraEdit, or even the default text editor gEdit in Linux distributuions using GNOME.