Build an Emoji Reactor - Step 11

Tell us what’s happening:

i need help here,
i tried to build the logic to make the update count work with any button but i still can’t pass !
any hint / help here
thank you

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Emoji Reactor</title>
  <link rel="stylesheet" href="./styles.css" />
</head>
<body>
  <main>

    <h1 class="title">How are you feeling today?</h1>

    <p class="description">
      Click on the buttons below to rate your emotions.
    </p>
    <div class="btn-container">
      <button id="happy-btn" class="emoji-btn" aria-label="Happy face emoji">
        <span role="img" aria-hidden="true">😊</span>
        <span class="count">0/10</span>
      </button>
    </div>
  </main>
  <script src="./script.js"></script>
</body>
</html>
/* file: styles.css */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --light-grey: #efefef;
  --white: #ffffff;
  --very-dark-blue: #0a0a23;
  --light-purple: #a78bfa;
  --very-light-purple: #c4b5fd;
  --purple: #8b5cf6;
}

body {
  background-color: var(--very-dark-blue);
  color: var(--light-grey);
  font-family: sans-serif;
}

main {
  text-align: center;
  padding: 10px;
}

.btn-container,
button {
  display: flex;
  justify-content: space-evenly;
  align-items: center;
}

.btn-container {
  flex-direction: column;
}

.emoji-btn {
  width: 70%;
  cursor: pointer;
  color: var(--white);
  background-color: var(--light-purple);
  background-image: linear-gradient(
    to bottom,
    var(--very-light-purple),
    var(--light-purple)
  );
  border: 3px solid var(--purple);
  border-radius: 8px;
  padding: 10px;
  font-size: 1.5rem;
  margin: 10px 0;
  transition: background-color 0.3s ease, transform 0.2s ease;
}

@media (min-width: 768px) {
  .emoji-btn {
    width: 30%;
  }
}

.emoji-btn:hover {
  background-color: var(--purple);
  background-image: none;
}

.title {
  margin-top: 15px;
  font-size: 2rem;
}

.description {
  font-size: 1.4rem;
  margin: 20px 0;
}
/* file: script.js */

// User Editable Region

const happyBtn = document.querySelector("#happy-btn");

// happyBtn.addEventListener("click", () => {
//   const countEl = happyBtn.querySelector(".count");
//   let currCount = +countEl.textContent.split("/")[0];
//   if (currCount === 10) return;
//   currCount++;
//   countEl.textContent = `${currCount}/10`;
// })
happyBtn.addEventListener('click', updateCount(happyBtn))
function updateCount(button) {
    const countEl = button.querySelector(".count");
    let currCount = +countEl.textContent.split("/")[0];
    if (currCount === 10) return;
    currCount++;
    countEl.textContent = `${currCount}/10`;
  console.log(countEl) 
  
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36

Challenge Information:

Build an Emoji Reactor - Step 11

Hi @SamehCode01

Review how to call a function when using an event listener.

The syntax is a bit different.

Happy coding

i think i should call it without arguments and also without parentheses ()

if you write no parentheses then you are not calling the function, depending on what you are going to write that could be correct

ok i will try to re-read it again and again to get it

ok i modified the function as it required but i can’t pass still
check , here is my updated code

const happyBtn = document.querySelector("#happy-btn");

// happyBtn.addEventListener("click", () => {
//   const countEl = happyBtn.querySelector(".count");
//   let currCount = +countEl.textContent.split("/")[0];
//   if (currCount === 10) return;
//   currCount++;
//   countEl.textContent = `${currCount}/10`;
// })
happyBtn.addEventListener('click', updateCount)
function updateCount(e) {
    const countEl = e.target.querySelector(".count");
    let currCount = +countEl.textContent.split("/")[0];
    if (currCount === 10) return;
    currCount++;
    countEl.textContent = `${currCount}/10`;
  console.log( currCount) 

  // console.log(e.target.querySelector('.count').textContent.split('/')[0])

}
1 Like

it still want me to pass the button as an argument to the function call but i don’t know still how to get it

1 Like

you need to pass a specific argument to updateCount, so you must give it an argument

can you think of a way to write updateCount with happyBtn but still pass a function (not a function call) to the event listener?

hint: it does not have to be the same function

1 Like

yes , i did it i did it . i passed it , i can’t believe it :slight_smile:

1 Like