Is it a glitch or something? Very confused right now


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-ZA2rb/0/6?curriculum_id=506324b3a7dffd00020bf661


For some reason, I had written three different objects, but as I answered my prompt with the third choice(barbarian), it displayed the properties of the first choice(knight). I am very confused, and very annoyed. Also, there are no syntaxErrors whatsoever.


confirm("You are playing 'The Last Hero'");
function hero(health, speed, armor) {
    this.health = health;
    this.speed = speed;
    this.armor = armor;
}
var barbarian = new hero(50, 12, 3);
var valkyrie = new hero(30, 20, 1);
var knight = new hero(42, 15, 2);

var player = prompt("You can choose from three classes, KNIGHT, VALKYRIE and BARBARIAN. Which do you choose?").toLowerCase();

if (player = barbarian) {
    confirm("Here are the stats of your choice.");
    confirm("Health: " + barbarian.health + "," + "Speed: " + barbarian.speed + "," + "Armor: " + barbarian.armor + ".");
} else if (player = valkyrie) {
    confirm("Here are the stats of your choice.");
    confirm("Health: " + valkyrie.health + "," + "Speed: " + valkyrie.speed + "," + "Armor: " + valkyrie.armor + ".");
} else if (player = knight) {
    confirm("Here are the stats of your choice.");
    confirm("Health: " + knight.health + "," + "Speed: " + knight.speed + "," + "Armor: " + knight.armor + ".");
} else {
    confirm("?")
}
 

function deadly(damage, weight, ammo, fireRate) {
    this.damage = damage;
    this.weight = weight;
    this.ammo = ammo;
    this.fireRate = fireRate;
}
var fireSword = new deadly(75, 20, 0, 1);
var lightningBow = new deadly(50, 15, 100, 0.5);
var antimatterRifle = new deadly(200, 30, 25, 5);
var weapon = prompt("Do you choose a fireSword, lightningBow or antimatterRifle? Please answer as shown.");
if (weapon = fireSword) {
    confirm("Here are the stats of your choice.");
    confirm("Damage: " + fireSword.damage + "," + "Weight: " + fireSword.weight + "," + "Ammo: " + fireSword.ammo + "," + "Firerate: " + fireSword.fireRate + ".");
} else if (weapon = lightningBow) {
    confirm("Here are the stats of your choice.");
    confirm("Damage: " + lightningBow.damage + "," + "Weight: " + lightningBow.weight + "," + "Ammo: " + lightningBow.ammo + "," + "Firerate: " + lightningBow.fireRate + ".");
} else if (weapon = antimatterRifle) {
    confirm("Here are the stats of your choice.");
    confirm("Damage: " + antimatterRifle.damage + "," + "Weight: " + antimatterRifle.weight + "," + "Ammo: " + antimatterRifle.ammo + "," + "Firerate: " + antimatterRifle.fireRate + ".");
} else {
    confirm("Sry, Whaa????")
}

//Would kindly appreciate it if someone could solve my confusing problem, thanks!


#2

Comparisons must be written with ===.


#3

Thank you so much:joy:! I forgot about using '===' for comparison, thank you for your help! (I'll try to remember next time:smile:


#4

Sorry. :joy: and :smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.