0

var soldier = {
    allegiance : "Ford" ,
    armor: True,
    weapon: "sword" 
};

document.getElementById("soldier").innerHTML = " allegiance: " + soldier.allegiance + " <br/> " + " armor: + " soldier.armor + "Weapon(s): "+ soldier.weapon;
<DOCTYPE HTML>

<html>
<head>
    <script src = "objscript.js" </script>
</head>

<body>
    <p id = "soldier"> </p>

</body>
</html>

I know this is probably the easiest thing but I don't know what it is. I'm trying to make an object that just prints out the items in the object.

Matt
  • 1,062
  • 1
  • 8
  • 11
Brandon Bell
  • 15
  • 1
  • 1
  • 4

1 Answers1

1

Your script is missing a closing > tag.

Plus, it most probably gets executed before the #soldier is visible. Thus it throws an error. Here you can find how to execute code after document is ready for it

Also, your + next to armor should be outside the quotes.

Also true should be all lowercase.

Here's a fix:

var soldier = {
  allegiance: "Ford",
  armor: true,
  weapon: "sword"
};

document.getElementById("soldier").innerHTML = " allegiance: " + soldier.allegiance + " <br/> " + " armor: " +
soldier.armor + "Weapon(s): " + soldier.weapon;
<DOCTYPE HTML>

  <html>

  <head>
  
    <script src = "objscript.js"> </script>
  </head>

  <body>
    <p id="soldier"> </p>

  </body>

  </html>
Unamata Sanatarai
  • 6,475
  • 3
  • 29
  • 51
  • So, what you're saying is, this question was caused by a typo and therefore will not be useful to future visitors? – Kevin B Oct 17 '17 at 18:25