Tell us what’s happening:
i cannot figure out how to write this line display.style.${cartContainer}
display.style.cartContainer or
style.display.cartContainer
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
cartBtn.addEventListener("click", () => {
isCartShowing = !isCartShowing;
showHideCartSpan.textContent = isCartShowing ? "Hide" : "Show";
this.style.display += isCartShowing ? "block" : "none"
});
// 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/130.0.0.0 Safari/537.36
Challenge Information:
Learn Basic OOP by Building a Shopping Cart - Step 40
Teller
November 4, 2024, 6:09pm
2
Hi @julieperk
Finally, update the display
property of the style
object of the cartContainer
variable to another ternary which checks if isCartShowing
is true. If it is, set the display
property to "block"
, otherwise set it to "none"
.
Check which variable you need to access.
The structure will be similar to the one above.
Happy coding
I don’t understand I’m using the cartContainer variable
display.style.cartContainer += isCartShowing ? display.block : display.none
I’m confused can you give me an example in the right syntax?
Teller
November 4, 2024, 6:34pm
5
The variable is showHideCartSpan
It goes at the start of the expression. Also note, you use the assignment operator not the compound assignment operator.
now I have this and now the ternary operator is wrong
showHideCartSpan.cartContainer.style.display === isCartShowing ? “block” : “none”
Teller
November 4, 2024, 6:37pm
7
Use just one variable, do not use strict equality operator.
i have to use an assignment operator +=?
Teller
November 4, 2024, 6:40pm
9
Do not use the compound assignment operator, use assignment operator like the code above.
I am still confused about the two variable thing? I tried cartContainer by itself.
showHideCartSpan.cartContainer = style.display = isCartShowing ? display= “block” : display = “none”
now i’m stuck on step 42 I’ll create a new topic
2 Likes