Nothing is being saved at local storage

I started writing JS code 3 weeks ago and currently I am trying to build a game-however for the past couple of days ran into a problem concerning the way I use local storage- basically the data is not being displayed on a page refresh-it is not being saved- here is the relevant part of my js file. One final thing that i wanted to add is that the browser also gives me the feedback that objectForMonsterMarkers.push is not a function – I tried to fix it, but I could not.

let playerCharachteristics = JSON.parse(localStorage.getItem('playerCharachteristics'));
let monsterCharachteritics = JSON.parse(localStorage.getItem('monsterCharachteritics'));
let objectForMonsterMarkers = JSON.parse(localStorage.getItem('monsterBooleanImage'));

if (objectForMonsterMarkers === null) {
  objectForMonsterMarkers = [];
};

if (playerCharachteristics || monsterCharachteritics === null) {

  playerCharachteristics = {
    pStrength: parseInt(Math.random() * 80), //stands for attack points, which are then increased in monsterhit pStrengthBar: parseInt (Math.random() * 80), pDefence: parseInt(Math.random() *70), pDefenceBar:parseInt (Math.random() * 80), pHealth: parseInt(Math.random() * 100), pHealthBar:true };

    monsterCharachteritics = {
      mStrength: 40,
      mStrengthBar: true,
      mDefence: parseInt(Math.random() * 80),
      mDefenceBar: parseInt(Math.random() * 80),
      mHealth: parseInt(Math.random() * 110),
      mHealthBar: parseInt(Math.random() * 80)
    };
  }
  else if (playerCharachteristics || monsterCharachteritics === null) {

    generateMonster(objectForMonsterMarkers);
  }

  function generateMonster(monsterBooleanImage) {

    let monsterHealthAdditionalHealthPoints = 800;

    console.log(monsterCharachteritics.mHealth);

    if (monsterBooleanImage === true) {
      console.log(monsterBooleanImage);
      divImage.innerHTML += `
      <img alt="" class="first" fetchpriority="auto" loading="auto"
              src="https://i.pinimg.com/564x/85/c8/f3/85c8f3eca9a5cbdef756956ba16b89dd.jpg" 
              id="gameCanvas" width="270" height="330" >
      `
      monsterHealthDiv.innerHTML += `
        <div id="monsterhealthbar"> 
            <div class="monsterhealthfill" > 
                <i class="hp3"> Monster Health
                </i>
            </div>
        </div> 
        <div id="monsterstrengthbar"> 
        <div class="monsterstrengthfill" > 
            <i class="hp3"> Monster Strength
            </i>
        </div>
    </div> 
    `
      monsterSDFbarFills.mhFill = document.querySelector(".monsterhealthfill");
      monsterCharachteritics.mHealthBar = document.querySelector("#monsterhealthbar");
      monsterCharachteritics.mStrengthBar = document.querySelector("#monsterstrengthbar")
      monsterSDFbarFills.msFill = document.querySelector(".monsterstrengthfill");
      monsterCharachteritics.mHealth += monsterHealthAdditionalHealthPoints;
      //monsterCharachteritics.mHealthBar= monsterHealthBar;

      monsterCharachteritics.mHealthBar.style.width = monsterCharachteritics.mHealth + 'px';
      monsterCharachteritics.mStrength = 35; //that is base monster strength
      monsterSDFbarFills.mhFill.innerHTML = `
            <i class="hp3"> Monster Health Points -${monsterCharachteritics.mHealth}</i>
            `;
      monsterSDFbarFills.msFill.innerHTML = `
            <i class="hp3"> Monster Strength Points -${monsterCharachteritics.mStrength}</i>
            `;
      checker2++;
      if (checker2 === 1) {
        divThrowButon.innerHTML = `
         <button onclick="throwForStrengthHealth()"> Throw For Health and Base Strength</button> 
         `;
      }
      console.log(monsterBooleanImage);

      // <div id="deletebutton"> bezshe v divthrowbuton
      attackDiv.innerHTML = `        <button class="button"  onclick="monsterHit(${monsterBooleanImage})">Attack</button>        `;
      // moveButton.innerHTML=``;
      console.log(monsterBooleanImage);

      localStorage.setItem('monsterBooleanImage', JSON.stringify(monsterBooleanImage));
      localStorage.setItem('playerCharachteristics', JSON.stringify(playerCharachteristics));
      localStorage.setItem('monsterCharachteritics', JSON.stringify(monsterCharachteritics));

    }

  }

  function monsterHit(booleanGameMechanics) {
    console.log(booleanGameMechanics);
    let playerThrowAdditionalAttackPoints = parseInt(Math.random() * 80);
    let overallPlayerDamage = playerCharachteristics.pStrength + playerThrowAdditionalAttackPoints;
    let monsterThrowAdditionalAttackPoints = parseInt(Math.random() * 90);
    let overallMonsterDamage = monsterThrowAdditionalAttackPoints + monsterCharachteritics.mStrength;

    if (booleanGameMechanics === true) {
      console.log(booleanGameMechanics + 'isTrue');
      if (overallMonsterDamage > overallPlayerDamage) {
        attackExchangeCounter++
      }
      if (attackExchangeCounter >= 3) {
        attackDiv.innerHTML = `
                     `;
        attackDiv.innerHTML = `
                     <button onclick="secondAttack(${overallMonsterDamage},${booleanGameMechanics})"> Second Attack</button>
                     <button onclick="lowerYourAttackPoints(${booleanGameMechanics})"> Lower your attack points</button>
                     `
        attackExchangeCounter = 0;
      }
      playerCharachteristics.pHealth -= overallMonsterDamage;
      console.log(playerCharachteristics.pHealth);
      monsterCharachteritics.mHealth -= overallPlayerDamage;

      if (overallMonsterDamage > 50) {
        objectHealthWidth.widthForHealth -= 50;
      } else if (overallMonsterDamage > 100) {
        objectHealthWidth.widthForHealth -= 100;
      } else {
        objectHealthWidth.widthForHealth -= 20
      }
      console.log(playerCharachteristics.pHealthBar);
      console.log(playerCharachteristics.pHealthBar.style.width);
      playerCharachteristics.pHealthBar.style.width = objectHealthWidth.widthForHealth + "px";
      monsterCharachteritics.mHealthBar.style.width = monsterCharachteritics.mHealth + "px";

      console.log(playerCharachteristics.pHealthBar);
      console.log(playerCharachteristics.pHealthBar.style.width);



      monsterCharachteritics.mStrengthBar.style.width = monsterCharachteritics.mStrength * 10 + "px";

      monsterSDFbarFills.mhFill.innerHTML = `
                   <i class="hp3"> Monster Health Points -${monsterCharachteritics.mHealth}</i>
                   `;
      monsterSDFbarFills.msFill.innerHTML = `
                   <i class="hp3"> Monster Strength Points -${monsterCharachteritics.mStrength}</i>
                   `;
      streDefeHealthBarFills.hFill.innerHTML = `
                   <i class="i">Health Points -${playerCharachteristics.pHealth}</i>
                   `;
      riddleContainer.innerHTML = `
                   <i class="hp3"> You dealt ${overallPlayerDamage} health points worth of damage to your opponent!</i>
                   <i class="hp3"> You received an overall damage of ${overallMonsterDamage} health points by your opponent!</i>
                   `


      if (monsterCharachteritics.mHealth < 0) {
        playerCharachteristics.pHealth += 300;

        healtWidth = 1450;
        playerCharachteristics.pHealthBar.style.width = healtWidth + "px"; //just for style,not accurate-cant reflect length with the actual points sadly
        moveButton.innerHTML += `
                       <button class="Move" onclick="move()"> Throw Dice To Move</button>
                       `;
        divImage.innerHTML = ``;
        monsterHealthDiv.innerHTML = ``;
        attackDiv.innerHTML = ``;
        riddleContainer.innerHTML = ``;
        streDefeHealthBarFills.hFill.innerHTML = `
                   <i class="i">Health Points -${playerCharachteristics.pHealth}</i>
                   `;
      }
      if (playerCharachteristics.pHealth < 0) {
        mainContainer.style.backgroundColor = "red";
        mainContainer.innerHTML = `
                      <i class="hp6"> GAME OVER! YOU DIED!
                      </i>
                      `;
      }
      localStorage.setItem('playerCharachteristics', JSON.stringify(playerCharachteristics));
      localStorage.setItem('monsterCharachteritics', JSON.stringify(monsterCharachteritics));
      localStorage.setItem('monsterBooleanImage', JSON.stringify(booleanGameMechanics));

    }
  }

New contributor

CFHVDOPFBD is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật