'Uncaught TypeError: Cannot read properties of undefined (reading 'add') - Wont add
Can anyone help me, I have been working on a project and cannot for the life of me work out why some of these work, and the lines such as 'queens' doesnt add or remove the classes...
I am attempting to make it so it verifies each line, checks if the current card is (for example) the ace of hearts, 'aceh', if so it add the current class, after this it then removes it once it is added to the prevcard var.
At the same time of adding it to the prevcard var, it adds another random card, lets say 'kingc' to the current card var... However it doesn't add the class to some of the vars and doesn't remove from others.
//CARD VERIFYING
if (currentcard == 'aceh'){aceh.classList.add('current')};
if (prevcard == 'aceh'){aceh.classList.add('prev')};
if (currentcard == 'aced'){aced.classList.add('current')};
if (prevcard == 'aced'){aced.classList.add('prev')};
if (currentcard == 'acec'){acec.classList.add('current')};
if (prevcard == 'acec'){acec.classList.add('prev')};
if (currentcard == 'aces'){aces.classList.add('current')};
if (prevcard == 'aces'){aces.classList.add('prev')};
if (currentcard == 'twoh'){twoh.classList.add('current')};
if (prevcard == 'twoh'){twoh.classList.add('prev')};
if (currentcard == 'twod'){twod.classList.add('current')};
if (prevcard == 'twod'){twod.classList.add('prev')};
if (currentcard == 'twoc'){twoc.classList.add('current')};
if (prevcard == 'twoc'){twoc.classList.add('prev')};
if (currentcard == 'twos'){twos.classList.add('current')};
if (prevcard == 'twos'){twos.classList.add('prev')};
if (currentcard == 'threeh'){threeh.classList.add('current')};
if (prevcard == 'threeh'){threeh.classList.add('prev')};
if (currentcard == 'threed'){threed.classList.add('current')};
if (prevcard == 'threed'){threed.classList.add('prev')};
if (currentcard == 'threec'){threec.classList.add('current')};
if (prevcard == 'threec'){threec.classList.add('prev')};
if (currentcard == 'threes'){threes.classList.add('current')};
if (prevcard == 'threes'){threes.classList.add('prev')};
if (currentcard == 'fourh'){fourh.classList.add('current')};
if (prevcard == 'fourh'){fourh.classList.add('prev')};
if (currentcard == 'fourd'){four.classList.add('current')};
if (prevcard == 'fourd'){four.classList.add('prev')};
if (currentcard == 'fourc'){four.classList.add('current')};
if (prevcard == 'fourc'){four.classList.add('prev')};
if (currentcard == 'fours'){four.classList.add('current')};
if (prevcard == 'fours'){fours.classList.add('prev')};
if (currentcard == 'fiveh'){fiveh.classList.add('current')};
if (prevcard == 'fiveh'){fiveh.classList.add('prev')};
if (currentcard == 'fived'){fived.classList.add('current')};
if (prevcard == 'fived'){fived.classList.add('prev')};
if (currentcard == 'fivec'){fivec.classList.add('current')};
if (prevcard == 'fivec'){fivec.classList.add('prev')};
if (currentcard == 'fives'){fives.classList.add('current')};
if (prevcard == 'fives'){fives.classList.add('prev')};
if (currentcard == 'sixh'){sixh.classList.add('current')};
if (prevcard == 'sixh'){sixh.classList.add('prev')};
if (currentcard == 'sixd'){sixd.classList.add('current')};
if (prevcard == 'sixd'){sixd.classList.add('prev')};
if (currentcard == 'sixc'){sixc.classList.add('current')};
if (prevcard == 'sixc'){sixc.classList.add('prev')};
if (currentcard == 'sixs'){sixs.classList.add('current')};
if (prevcard == 'sixs'){sixs.classList.add('prev')};
if (currentcard == 'sevenh'){sevenh.classList.add('current')};
if (prevcard == 'sevenh'){sevenh.classList.add('prev')};
if (currentcard == 'sevend'){sevend.classList.add('current')};
if (prevcard == 'sevend'){sevend.classList.add('prev')};
if (currentcard == 'sevenc'){sevenc.classList.add('current')};
if (prevcard == 'sevenc'){sevenc.classList.add('prev')};
if (currentcard == 'sevens'){sevens.classList.add('current')};
if (prevcard == 'sevens'){sevens.classList.add('prev')};
if (currentcard == 'eighth'){eighth.classList.add('current')};
if (prevcard == 'eighth'){eighth.classList.add('prev')};
if (currentcard == 'eightd'){eightd.classList.add('current')};
if (prevcard == 'eightd'){eightd.classList.add('prev')};
if (currentcard == 'eightc'){eightc.classList.add('current')};
if (prevcard == 'eightc'){eightc.classList.add('prev')};
if (currentcard == 'eights'){eights.classList.add('current')};
if (prevcard == 'eights'){eights.classList.add('prev')};
if (currentcard == 'nineh'){nineh.classList.add('current')};
if (prevcard == 'nineh'){nineh.classList.add('prev')};
if (currentcard == 'nined'){nined.classList.add('current')};
if (prevcard == 'nined'){nined.classList.add('prev')};
if (currentcard == 'ninec'){ninec.classList.add('current')};
if (prevcard == 'ninec'){ninec.classList.add('prev')};
if (currentcard == 'nines'){nines.classList.add('current')};
if (prevcard == 'nines'){nines.classList.add('prev')};
if (currentcard == 'tenh'){tenh.classList.add('current')};
if (prevcard == 'tenh'){tenh.classList.add('prev')};
if (currentcard == 'tend'){tend.classList.add('current')};
if (prevcard == 'tend'){tend.classList.add('prev')};
if (currentcard == 'tenc'){tenc.classList.add('current')};
if (prevcard == 'tenc'){tenc.classList.add('prev')};
if (currentcard == 'tens'){tens.classList.add('current')};
if (prevcard == 'tens'){tens.classList.add('prev')};
if (currentcard == 'jackh'){jackh.classList.add('current')};
if (prevcard == 'jackh'){jackh.classList.add('prev')};
if (currentcard == 'jackd'){jackd.classList.add('current')};
if (prevcard == 'jackd'){jackd.classList.add('prev')};
if (currentcard == 'jackc'){jackc.classList.add('current')};
if (prevcard == 'jackc'){jackc.classList.add('prev')};
if (currentcard == 'jacks'){jacks.classList.add('current')};
if (prevcard == 'jacks'){jacks.classList.add('prev')};
if (currentcard == 'queenh'){queenh.classList.add('current')};
if (prevcard == 'queenh'){queenh.classList.add('prev')};
if (currentcard == 'queend'){queend.classList.add('current')};
if (prevcard == 'queend'){queend.classList.add('prev')};
if (currentcard == 'queenc'){queenc.classList.add('current')};
if (prevcard == 'queenc'){queenc.classList.add('prev')};
if (currentcard == 'queens'){queens.classList.add('current')};
if (prevcard == 'queens'){queens.classList.add('prev')};
if (currentcard == 'kingh'){kingh.classList.add('current')};
if (prevcard == 'kingh'){kingh.classList.add('prev')};
if (currentcard == 'kingd'){kingd.classList.add('current')};
if (prevcard == 'kingd'){kingd.classList.add('prev')};
if (currentcard == 'kingc'){kingc.classList.add('current')};
if (prevcard == 'kingc'){kingc.classList.add('prev')};
if (currentcard == 'kings'){kings.classList.add('current')};
if (prevcard == 'kings'){kings.classList.add('prev')};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
