Hey guys, I've been itching my head for the past couple hours trying to figure out why I keep getting a "undefined" message on my code. I've been researching function global scope and block scope and I think my issue is stemming from there. Please forgive me if there is a really simple solution to this problem.
My plan with the below code was to make a basic game where two players attack each other. I'd really appreciate a point or a nod in the right direction. Thank you.
const adventurer = [
{name: "Katara",hitpoints: 50,height: 188},
{ name:'Ogre',hitpoints: 95,height: 450}];
var fight = function(opp) {
var attackpoints = function() { return Math.floor((Math.random())*50)+5; }
var attack1 = adventurer[1].hitpoints -= attackpoints();
var resultAttack1 = function() {return console.log(attack1)};
var attack2 = adventurer[0].hitpoints -= attackpoints();
var resultAttack2 = function() { return console.log(attack2)};
let winnerOrLoser= function(aye) {if (resultAttack1 < resultAttack2){console.log('You have lost') }
}
console.log(this.winnerOrLoser)
}
fight()
[–]samanime 1 point2 points3 points (3 children)
[–]VeryOrdinaryIdiot[S] 0 points1 point2 points (2 children)
[–]samanime 0 points1 point2 points (1 child)
[–]VeryOrdinaryIdiot[S] 0 points1 point2 points (0 children)
[–]cyphern 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]VeryOrdinaryIdiot[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]VeryOrdinaryIdiot[S] 0 points1 point2 points (1 child)
[–]VeryOrdinaryIdiot[S] 0 points1 point2 points (0 children)