W
W
WarriorKodeK2018-02-15 19:31:32
JavaScript
WarriorKodeK, 2018-02-15 19:31:32

Why doesn't it pass the test?

Good evening everyone. Please tell me why the function does not pass the test for me:

const checkBingo = num => {
  const cells = document.querySelectorAll('.cell');
  cells.forEach(cell => {
    if (сell.textContent === num) {
      cell.classList.add('flip');
    }
  });
};

It should check the numbers in the cells with the generated numbers and if it matches, then change the background.
Here is the code - https://codepen.io/anon/pen/LQOYVd
Functions checkBingoand createBall
Please tell me why it doesn't work.
Thank you very much!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-02-15
@WarriorKodeK

if (cell.textContent === num) {

Let me guess - num is a number, right? Sensation! Shock! - number cannot be equal to string.
Compare with cast:
if (cell.textContent == num) {
Or convert string to number:
if (+cell.textContent === num) {

T
tyzberd, 2018-02-15
@tyzberd

if (cell.textContent === num) {
      cell.classList.add('flip');
    }

in the condition somewhere a string, somewhere a number.
with == works

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question