Group of buttons: start disabled

Group of buttons: start disabled
0

I made a class of buttons “factPick” and I’d like them to start disabled (except for the zeroes) and then become active as people progress.

<button class="button1 factPick" id="oneButton"  onclick="pickFact(0);">Zeroes</button>

( https://codepen.io/geonz/pen/qBBoVbO )
Is there a way to declare a whole class of buttons disabled with CSS? Nothing I’ve tried works. Other stuff like changing color works…
(e.g.:

.factPick
{
/*    background-color: white; */
  disabled: true;
}

( I know I could just label each individual one “disabled” to start with.)

I could be wrong, but I think the only way to disable an element (only certain ones have this attribute) is to set the disabled attribute to true within the element tag (as you already know how to do). You can update he attribute’s value via JavaScript. Anything using CSS would inevitably be a “hack” and may not work on all browsers.

Thanks! I just wanted to make sure I wasn’t a properly placed parenthesis away from making it work…

@geonz I took your project and refactored a bit, so you can see an alternative way of creating all of the fact groups without having to hard code them. I kept it simple with respect to the order of the facts. You can check the browser console after clicking to see the array of facts created when clicking on a number button to see how my logic arranged them. Personally would randomly select (without replacement) one of the facts for each test, but this is your quiz and you can do what you want with it.

I also dynamically create the buttons, because I like to keep code as DRY (Do Not Repeat Yourself) as possible.

Feel free to use the code and tweak it a bit more to your liking. I recommend clicking the open in repl.it link at the top right corner of the embedded code below.

This is something I was trying to figure out… I have made some things in Geogebra with sequences so I didn’t have to list all… those… facts… I’ll be thinking :wink:
(and I’m planning to have an “in order” version and then a random version… but also versions with visual representations of various sorts.)

Question… what is this called:

const choices = {
  0: "Zeros", 1: "Ones", 2: "Twos", 3: "Threes",
  4: "Fours", 5: "Fives", 6: "Sixes", 7: "Sevens",
  8: "Eights", 9: "Nines", 10: "Tens"
};

… is it an object with ten ‘properties’? (I’d never have thought to do that… )

and… what does the $ mean in ${choices[factChoice]} ?

Just an object lookup which is discussed in the Using Objects for Lookups challenge

You will learn about template literals in the ES6 section.

1 Like