Skip to content

Experience is added as a string instead of a number #4

@GitJohnFis

Description

@GitJohnFis

Bug

In script.js, when a monster is defeated, the experience (exp) variable is incremented with the monster's name (a string) instead of their level (a number). This causes experience to become a string, which breaks experience tracking and related calculations.

Problematic code:
exp += monsters[fighting].name;

Expected behavior:
Experience should be increased by the monster's level (a number), e.g.:
exp += monsters[fighting].level;

Steps to Reproduce

  1. Defeat a monster in the game.
  2. Check the experience value displayed or in the console.
  3. Notice that the value is a string and not incrementing as expected.

Suggested Fix

Update the relevant line to add the monster's level to the experience:
exp += monsters[fighting].level;

Additional Context

This is an easy and impactful fix for new contributors!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions