I have written some JavaScript code to do something when some buttons are click. However, when I click on the buttons, it returns a typeError. Uncaught TypeError: Cannot read property ‘saidOrNot’ of undefined.
How do I fix it? JS Code below –
var score = 0;
var wrong_sound = new Audio("sounds/wrong.mp3");
var trumpStatements_p = document.getElementById("trump-statement-p");
var scoreBoard_p = document.getElementById("score-board-p");
var yes_btn = document.getElementById("yes-btn");
var no_btn = document.getElementById("no-btn");
// Trump Statement object
class trumpStatement {
constructor(statement, saidOrNot) {
this.statement = statement;
this.saidOrNot = saidOrNot;
}
}
// Create the Trump Statement Objects
var rocketMan = new trumpStatement("The US has great strength and patience, but if it is forced to defend itself and its allies, we will have no choice but to totally destroy North Korea. ROCKET MAN is on a suicide mission for himself and for his regime.", true);
var wall = new trumpStatement("I would build a great wall, and nobody builds walls better than me, believe me, and I’ll build them very inexpensively, I will build a great, great wall on our southern border. And I will have Mexico pay for that wall.", true);
var whiteSupremecy = new trumpStatement("I stand back, and stand by. (while referencing white supremacists)", true);
var greatest = new trumpStatement("I’m the greatest President ever with the <em>possible</em> exception of Lincoln.", true);
var chinaLunch = new trumpStatement("China ate your lunch, Joe.", true);
var obamasDogImmigrant = new trumpStatement("Yeah, Obama had a dog. You're right. Both parties should come together to finally create a safe and lawful system of immigration.", true);
var kenyanObama = new trumpStatement("Obama was born in Kenya! Again, immigrants taking our jobs!", false);
var openAmerica = new trumpStatement("Make America Open Up Again. (in reference to Covid-19 lockdowns)", false);
var nukeKorea = new trumpStatement("If North Korea doesn’t stop their nuclear tests, for America’s security, I will have no choice but to nuke them.", false);
var trade = new trumpStatement("President Xi and I had major disagreements over trade. We are working on a trade deal and I will make sure that the deal puts AMERICA FIRST.", false);
// Store all statements in a variable
var statements = [rocketMan, wall, whiteSupremecy, greatest, chinaLunch, obamasDogImmigrant, kenyanObama, openAmerica, nukeKorea, trade];
function right(statementInd) {
statements.splice(statementInd);
statementIndex = Math.floor(Math.random() * statements.length);
saidOrNot = statements[statementIndex].saidOrNot;
statement = statements[statementIndex].statement;
trumpStatements_p.innerHTML = statement;
score++;
scoreBoard_p.innerHTML = `You have got ${score}/10 correct`;
// animation
document.getElementsByTagName("body")[0].classList.add("right");
setTimeout(function() {
document.getElementsByTagName("body")[0].classList.remove("right");
}, 400);
}
function wrong(statementInd) {
statements.splice(statementInd);
statementIndex = Math.floor(Math.random() * statements.length);
saidOrNot = statements[statementIndex].saidOrNot;
statement = statements[statementIndex].statement;
trumpStatements_p.innerHTML = statement;
// animation and sound
document.getElementsByTagName("body")[0].classList.add("wrong");
setTimeout(function() {
document.getElementsByTagName("body")[0].classList.remove("wrong");
}, 400);
wrong_sound.play();
}
var statementIndex = Math.floor(Math.random() * statements.length);
var saidOrNot = statements[statementIndex].saidOrNot;
var statement = statements[statementIndex].statement;
trumpStatements_p.innerHTML = statement;
yes_btn.addEventListener("click", function() {
if (statements[statementIndex].saidOrNot === true) {
right(statementIndex);
} else {
wrong(statementIndex);
}
});
no_btn.addEventListener("click", function() {
if (statements[statementIndex].saidOrNot === true) {
right(statementIndex);
} else {
wrong(statementIndex);
}
});
Source code in GitHub Repository – https://github.com/Aaditya-Baduni/trump-statements
viagra price in us – where can i get cheap sildenafil viagra soft flavoured
ivermectin for covid 19 – buy ivermectin canada ivermectin 3mg tabs
buy cytotec india – cytotec for sale to us cytotec drug
500 mg doxycycline pill – doxycycline tablets buy online how to get doxycycline cheap
viagra soft gel – 35 viagra
buy cialis online with paypal – cialis 5mg generic
buy generic vardenafil no prescription – vardenafil prescriptions online how long does vardenafil take to work
prednisone online without a prescription – buy prednisone online nz prednisone online for sale
accutane cream for sale – how can i get accutane buy accutane online australia
kroger amoxicillin price – buying amoxicillin over the counter buy amoxicilina noscript canada
buying essays – write my essay help purchase essay online
ivermectin 8000 mcg – stromectol uk coronavirus stromectol generic name
purchase stromectol online – buy ivermectin 3mg cost of ivermectin pill
tadalafil 5 mg – tadalafil generic date tadalafil pill
viagra 100mg tablet – Mail order cialis brand name cialis canada
ivermectin 2% – buy oral ivermectin ivermectin 10 ml
tadalafil generic cost – 120 mg of cialis 80 mg cialis
prednisone 20mg tablets where to buy – prednisone without prescription medication prednisone buy online
stromectol online – ivermectin brand name ivermectin iv
tadalafil 100mg online – cheap cialis online tadalafil for sale online
ivermectin 6mg tablets for humans – stromectol oral solution buy oral stromectol
free slots online – casirealgam real money casino
assignment company – pay for research papers my future essay writing
sildenafil citrate 200mg – Sample viagra order viagra canada
ivermectin usa price – ivermectin pills cost stromectol
prednisone buy canada – prednisone 60mg medication how much is prednisone 20 mg
accutane for sale online – buy cheap accutane online buy generic accutane online
ivermectin – ivermectin dosage india ivermectin
ocean casino online – online card games casino online real money
pay essay writing – cheap essay writer term papers writing service
buy plaquenil generic – valacyclovir 1000mg usa order valtrex 1000mg sale
sildalis for sale – sildalis online metformin 1000mg oral
order generic ampicillin 500mg – plaquenil 200mg cheap buy hydroxychloroquine 200mg online
plaquenil stomach problems hydroxychloroquine sulfate cost plaquenil/side effects mouth pictures what does plaquenil do for lupus
viagra tablet how to get viagra in usa over the counter viagra australia cialis how to take effectively
bupropion / naltrexone naltrexone uk price naltrexone interactions with other drugs how long is naltrexone in your system
men taking nolvadex generic nolvadex for sale nolvadex 30 mg price india how to cycle clomid and nolvadex
amoxil suspension dose amoxicillin for sale for humans 500 mg amoxicillin pediatric dosing why is my face red after amoxil
molnupiravir trial molnupiravir how to buy molnupiravir kaufen que contiene el molnupiravir
plaquenil surgery hydroxychloroquine sulfate tablets sd-oct and plaquenil toxicity what is plaquenil for
amoxil for uti where to buy amoxicillin 500mg amoxicillin 800 mg amoxil before or after food