Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question: Can\'t seem to get the following code to run Please help pinpoint erro

ID: 3675528 • Letter: Q

Question

Question: Can't seem to get the following code to run Please help pinpoint error???

<!DOCTYPE html>
<html>
<head>
   <title>Greg's Gambits | The Battleground</title>
   <link href="greg.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8" />
  
<script type="text/javascript">

function battleIt()
{
       var heroPlay = 0; var trollPlay = 0;
       var heroPts = 100; var trollPts = 100;
       var rocks = "magic rocks"; var sword = "the sword";
       var arrow = "bow and arrow";
       var heroChoice = " "; var trollChoice = " ";
      
       document.getElementById("trollPts").innerHTML = (trollPts);
       document.getElementById("heroPts").innerHTML = (heroPts);
       document.getElementById("playerWeapon").innerHTML = ("Your weapon: ");
       document.getElementById("trollWeapon").innerHTML = ("The Troll's weapon: ");
       document.getElementById("winner").innerHTML = ("&nbsp;");
      
       //loop repeats until troll or player get 130 points
        while ((trollPts < 130) && (heroPts < 130))
       {
           heroPlay = parseInt.prompt (" What weapon do you choose? Enter 1 for magic rocks (enter 1), 2 for the sword,
                                   or 3 for the bow and arrow: (Enter 4 to leave) ");
           if (heroPlay == 4) break;
           // get troll's weapon
           trollPlay = Math.floor(Math.random() * 3 + 1);
          
           // assign weapon to player and troll
           if (trollPlay == 1)
               trollChoice = rocks;
           if (trollPlay == 2)
               trollChoice = sword;
           if (trollPlay == 3)
               trollChoice = arrow;
           if (heroPlay == 1)
               heroChoice = rocks;
           if (heroPlay == 2)
               heroChoice = sword;
           if (heroPlay == 3)
               heroChoice = arrow;
          
           //display weapon selections
           document.getElementById("playerWeapon").innerHTML = ("Your weapon: " + heroChoice);
           document.getElementById("trollWeapon").innerHTML = ("The troll's weapon: " + trollChoice);
           alert("This round of the battle begins now!");
          
           //find the winner
           if (((trollPlay == 1) &&(heroPlay == 3)) || ((trollPlay == 2)
                              &&(heroPlay == 1)) || ((trollPlay == 3)
                              &&(heroPlay == 2)))
          
           {
               document.getElementById("winner").innerHTML = ("<img src="images/troll.jpg" />");
               trollPts = trollPts + 10;
               heroPts = heroPts - 10;
               document.getElementById("trollPts").innerHTML = (trollPts);
               document.getElementById("heroPts").innerHTML = (heroPts);
           }
          
           if (((heroPlay == 1) &&(trollPlay == 3)) || ((heroPlay == 2)
                               &&(trollPlay == 1)) || ((heroPlay == 3)
                               &&(trollPlay == 2)))
           {
               document.getElementById("winner").innerHTML = ("<img src="images/wizard.jpg" />");
               trollPts = trollPts - 10;
               heroPts = heroPts + 10;
               document.getElementById("trollPts").innerHTML = (trollPts);
               document.getElementById("heroPts").innerHTML = (heroPts);
           }
          
           if (((heroPlay == 1) &&(trollPlay == 1)) || ((heroPlay == 2)
                               &&(trollPlay == 2)) || ((heroPlay == 3)
                               &&(trollPlay == 3)))
           {
               document.getElementById("winner").innerHTML = ("This round is a tie. New Weapons must be chosen...");
              
           }
       }
       //display the final winner
       if (heroPlay == 4)
           document.getElementById("winner").innerHTML = ("It's true: when you run, you live to fight another day. See you again soon!");
      
       if (trollPts >= 130)
           document.getElementById("The battle has been fought valiently but the troll has beaten you. Go home and nurse your wounds.");
      
       if (hero >= 130)
           document.getElementById("winner").innerHTML = ("The battle has been fought valiently and you have prevailed! Congratulations!");
  
}
</script>

<style type="text/css">
<!--
.style1 {font-size: 18px}
-->
</style>
</head>

<body>
<div id="container">
<img src="images/superhero.jpg" width="120" height="120" class="floatleft" alt=""/>
<h1>The Battleground</h1>
<div></div>
<div id="nav">
<p><a href="index.html">Home</a>
<a href="greg.html">About Greg</a>
<a href="play_games.html">Play a Game</a>
<a href="sign.html">Sign In</a>
<a href="contact.html">Contact Us</a></p>
</div>
<div id="content">
<table>
<tr><td><img src="images/wizard.jpg" width="120" height="168" alt="" /></td>
<td><img src="images/troll.jpg" width="120" height="168" alt="" /></td></tr>
<tr><td><span class="style1">Wizard uses: </span></td>
<td><span class="style1">Troll uses: </span></td></tr>
<tr><td id = "playerWeapon" class="style1">Weapon goes here</td>
<td id = "trollWeapon" class="style1">Weapon goes here</td></tr>
<tr><td colspan = "2" class="style1">The winner is:</td></tr>
  
<tr><td colspan = "2" id="winner" class="style1">&nbsp;</td></tr>
<tr><td><span class="style1">Wizard points: </span></td>
<td><span class="style1">Troll points:</span></td></tr>
<tr><td class="style1" id = "heroPts">100</td> <td class="style1" id = "trollPts">100</td></tr>

<tr><td><input type="button" id="battle" value="Let the battle begin!"/></td>

<td><input type="button" id="return" value="Return to battle instructions" /></td>

</tr>
</table>
</div>
<div id="footer">Copyright &copy; 2013 Greg's Gambits<br />
<a href="mailto:">email@mail.com</a>
</div>
</div>
</body>
</html>

Explanation / Answer

Use bellow code working fine and bellow line code error

      before change: heroPlay = parseInt.prompt (" What weapon do you choose? Enter 1 for magic rocks (enter 1), 2 for the sword,
                                   or 3 for the bow and arrow: (Enter 4 to leave) ");

after change :

heroPlay = parseInt(prompt("What weapon do you choose? Enter 1 for magic rocks (enter 1), 2 for the sword,or 3 for the bow and arrow: (Enter 4 to leave) "));

<!DOCTYPE html>

<html>
<head>
<title>Greg's Gambits | The Battleground</title>
<link href="greg.css" rel="stylesheet" type="text/css" />
<meta charset="utf-8" />
  
<script type="text/javascript">
function battleIt()
{
debugger;
var heroPlay = 0;
var trollPlay = 0;
var heroPts = 100;
var trollPts = 100;
var rocks = "magic rocks";
var sword = "the sword";
var arrow = "bow and arrow";
var heroChoice = " ";
var trollChoice = " ";
  
document.getElementById("trollPts").innerHTML = (trollPts);
document.getElementById("heroPts").innerHTML = (heroPts);
document.getElementById("playerWeapon").innerHTML = ("Your weapon: ");
document.getElementById("trollWeapon").innerHTML = ("The Troll's weapon: ");
document.getElementById("winner").innerHTML = ("&nbsp;");
  
//loop repeats until troll or player get 130 points
while ((trollPts < 130) && (heroPts < 130))
{
heroPlay = parseInt(prompt("What weapon do you choose? Enter 1 for magic rocks (enter 1), 2 for the sword,or 3 for the bow and arrow: (Enter 4 to leave) "));
if (heroPlay == 4) break;
// get troll's weapon
trollPlay = Math.floor(Math.random() * 3 + 1);
  
// assign weapon to player and troll
if (trollPlay == 1)
trollChoice = rocks;
if (trollPlay == 2)
trollChoice = sword;
if (trollPlay == 3)
trollChoice = arrow;
if (heroPlay == 1)
heroChoice = rocks;
if (heroPlay == 2)
heroChoice = sword;
if (heroPlay == 3)
heroChoice = arrow;
  
//display weapon selections
document.getElementById("playerWeapon").innerHTML = ("Your weapon: " + heroChoice);
document.getElementById("trollWeapon").innerHTML = ("The troll's weapon: " + trollChoice);
alert("This round of the battle begins now!");
  
//find the winner
if (((trollPlay == 1) &&(heroPlay == 3)) || ((trollPlay == 2)
&&(heroPlay == 1)) || ((trollPlay == 3)
&&(heroPlay == 2)))
  
{
document.getElementById("winner").innerHTML = ("<img src="images/troll.jpg" />");
trollPts = trollPts + 10;
heroPts = heroPts - 10;
document.getElementById("trollPts").innerHTML = (trollPts);
document.getElementById("heroPts").innerHTML = (heroPts);
}
  
if (((heroPlay == 1) &&(trollPlay == 3)) || ((heroPlay == 2)
&&(trollPlay == 1)) || ((heroPlay == 3)
&&(trollPlay == 2)))
{
document.getElementById("winner").innerHTML = ("<img src="images/wizard.jpg" />");
trollPts = trollPts - 10;
heroPts = heroPts + 10;
document.getElementById("trollPts").innerHTML = (trollPts);
document.getElementById("heroPts").innerHTML = (heroPts);
}
  
if (((heroPlay == 1) &&(trollPlay == 1)) || ((heroPlay == 2)
&&(trollPlay == 2)) || ((heroPlay == 3)
&&(trollPlay == 3)))
{
document.getElementById("winner").innerHTML = ("This round is a tie. New Weapons must be chosen...");
  
}
}
//display the final winner
if (heroPlay == 4)
document.getElementById("winner").innerHTML = ("It's true: when you run, you live to fight another day. See you again soon!");
  
if (trollPts >= 130)
document.getElementById("The battle has been fought valiently but the troll has beaten you. Go home and nurse your wounds.");
  
if (hero >= 130)
document.getElementById("winner").innerHTML = ("The battle has been fought valiently and you have prevailed! Congratulations!");
  
}
</script>
<style type="text/css">
<!--
.style1 {font-size: 18px}
-->
</style>
</head>
<body>
<div id="container">
<img src="images/superhero.jpg" width="120" height="120" class="floatleft" alt=""/>
<h1>The Battleground</h1>
<div></div>
<div id="nav">
<p><a href="index.html">Home</a>
<a href="greg.html">About Greg</a>
<a href="play_games.html">Play a Game</a>
<a href="sign.html">Sign In</a>
<a href="contact.html">Contact Us</a></p>
</div>
<div id="content">
<table>
<tr><td><img src="images/wizard.jpg" width="120" height="168" alt="" /></td>
<td><img src="images/troll.jpg" width="120" height="168" alt="" /></td></tr>
<tr><td><span class="style1">Wizard uses: </span></td>
<td><span class="style1">Troll uses: </span></td></tr>
<tr><td id = "playerWeapon" class="style1">Weapon goes here</td>
<td id = "trollWeapon" class="style1">Weapon goes here</td></tr>
<tr><td colspan = "2" class="style1">The winner is:</td></tr>
  
<tr><td colspan = "2" id="winner" class="style1">&nbsp;</td></tr>
<tr><td><span class="style1">Wizard points: </span></td>
<td><span class="style1">Troll points:</span></td></tr>
<tr><td class="style1" id = "heroPts">100</td> <td class="style1" id = "trollPts">100</td></tr>
<tr><td><input type="button" id="battle" value="Let the battle begin!"/></td>
<td><input type="button" id="return" value="Return to battle instructions" /></td>
</tr>
</table>
</div>
<div id="footer">Copyright &copy; 2013 Greg's Gambits<br />
<a href="mailto:">email@mail.com</a>
</div>
</div>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote