In the startGame()method, I am trying to store the selected phrase from the getRandomPhrase() method to the null property. It keeps throwing me an error saying
Game.activePhrase is null
What am I doing wrong?
Game.js:
class Game {
constructor() {
this.missed = 0;
//directly put the phrases in the constructor
this.phrases = [new Phrase("hello world"),
new Phrase("Wolf on wall street"),
new Phrase("Despite making"),
new Phrase("Karen took the kids"),
new Phrase("alright about to head out")
];
this.activePhrase = null;
}
getRandomPhrase() {
//returns 5 of the random phrases
return this.phrases[Math.floor(Math.random() * this.phrases.length)];
}
startGame() {
let hid = document.getElementById('overlay');
hid.style.display = "none";
let phrs = this.getRandomPhrase();
phrs.addPhraseToDisplay();
return this.activePhrase(phrs); //trying to store it by doing this
}
}
App.js
const game = new Game();
game.startGame();
console.log(`Active Phrase - phrase: ${game.activePhrase.phrase}`);
this.activePhrase = phrs;?