简体   繁体   中英

Why isn't my JavaScript printing to my HTML?

I learned AngularJS before I learned how to connect vanilla JS to HTML. When I run this code in my browser, the console.logs work, but the number 3 isn't showing up in my first die.

Can you help me fix my code?

JavaScript: var roll = document.getElementById('roll');

function Dice() {
  Document.write('1');
}

function printNumber() {
  var one = document.getElementById("one");
  one.innterHTML = "3";
  console.log('printNumber called!');
}

roll.onclick = function() {
  printNumber();
  console.log('rolled!');
};

HTML:

    <div class="row">
        <div class="dice" id="one">
        </div>
        <div class="dice" id="two">
            2
        </div>
    </div>
    <div class="row">
        <div class="button" id="roll">Roll the dice!</div>
    </div>
    <script type="text/javascript" src="dice.js"></script>

innter should be inner and Document should be document.

function Dice() {
  document.write('1');
}

function printNumber() {
  var one = document.getElementById("one");
  one.innerHTML = "3";
  console.log('printNumber called!');
}

roll.onclick = function() {
  printNumber();
  console.log('rolled!');
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM