variable doesn't change value | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

variable doesn't change value

why doesn't 'let right = 0' increase its value when I click on the target? const game = document.querySelector('.game'); let cards = []; const cardImg = 'url("img/cheese_'; let right = 0; for(i = 1; i < 5; i += 1){ cards.push(cardImg + i + '.png")'); } function playing (firstCard, lastCard, cardImg){ game.addEventListener('click', (e)=> matching(e, firstCard, lastCard, cardImg)); } function matching (e, firstCard, lastCard, cardImg) { if(e.target.className === firstCard || e.target.className === lastCard){ e.target.style.backgroundImage = cardImg; e.target.innerHTML = ''; right += 1; } }

4th Apr 2020, 1:30 PM
Francesco Paolini
Francesco Paolini - avatar
3 Answers
+ 2
sorry guys, from the time I wrote the question I kept changing the code and solved the problem at some point. Sorry for not posting the question the right way, i'll keep you update if i need it
5th Apr 2020, 9:43 AM
Francesco Paolini
Francesco Paolini - avatar
+ 1
You can touch on my profile and see my codes on sololearn. Here's a few rules. You have a question about an unpredictable functioning of your code. How do you imagine giving an answer with an incomplete code?
4th Apr 2020, 7:53 PM
JaScript
JaScript - avatar
0
Francesco Paolini hi, Did the console report any error message? You could post a link to your code if it is on sololearn.
4th Apr 2020, 2:33 PM
EmmanueLZ.
EmmanueLZ. - avatar