1

Учу js по книге Эрика Фримена. В 8 главе делают игру морской бой на js. Пишу код идентично, но возникает ошибка:

game.js:4 Uncaught TypeError: Cannot set property 'innerHTML' of null
at Object.displayMessage (game.js:4).

Если что могу докинуть код

var view = {
displayMessage: function(msg) {
    var messageArea = document.getElementById('#messageArea');
    messageArea.innerHTML = msg;
},

displayHit: function(location) {
    var cell = document.getElementById(location);
    cell.setAttribute("class", "hit");
},

displayMiss: function(location) {
    var cell = document.getElementById(location);
    cell.setAttribute("class", "miss");
}

};

1 ответ 1

2

У вас на странице нет элемента с id="#messageArea". Может быть у вас есть элемент с id="messageArea", но тогда нужно писать

var messageArea = document.getElementById('messageArea');

(без начального #)

2
  • Спасибо! Так и было 19 фев 2020 в 15:56
  • @ИванСорокин Если мой ответ решил вашу проблему, отметьте его как верный 19 фев 2020 в 15:59

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.