Assessment wanted for Scoreboard project

Hi,

I am encountering a problem with my code printing the right response when certain integers are imputed. It keeps printing only one response for all integers, which shouldn’t be the case. I am stuck and don’t know how to resolve this, please help.

Here’s a link to the pen on codepen : https://codepen.io/mitch-ihejirika/pen/eYZgqXz

Thanks.

Hi @mitchellihejirika, hope you are well today.

I like the improvements you’ve made to the example. This is really close to working; I noticed a couple of problems that need to be fixed.

The first one is concerning printing out the different score responses — this is because you are not creating a reference to the second input correctly. This is the line you are using:

const input = document.querySelector('input');

But document.querySelector() always selects the first instance of an element that matches the given selector on a page. In this case, that would be the checkbox, not the text input. So to fix this, you could simply use the following instead:

const input = document.getElementById('score');

The other thing I noticed is that you are using the following event handler to change the machineActive value:

machine.onchange = function() {
    machineActive = true;
}

Unfortunately, this causes the machineActive value to be set to true forever after the checkbox is first checked. To make the program behave correctly when the checkbox is checked and unchecked, you need to check whether it is checked, and set machineActive appropriately, for example this would work:

machine.onchange = function() {
  if(machine.checked) {
    machineActive = true;
  } else {
    machineActive = false;
  }
}

Great work though — I love seeing people make their own changes to the examples and try new things out!

1 Like

Awesome! I just made the corrections per your suggestions and it works perfectly now. Thanks a lot for your assistance.

p.s : big fan of your articles.

You are absolutely welcome, and I am so glad you are finding them useful.

1 Like