dia ♡
@diaasaurAll comments
- @Sorpanda@diaasaur
Hi Soraya! Great job on your first JS challenge <3
The showing and hiding of the 2 different elements (Survey and Thank you) after submitting was difficult
The task of showing and hiding the two elements (Survey and Thank you) after submitting can be challenging. Let's break down what you did to achieve this:
- You have two articles,
survey
andafterSubmit
, which are initially arranged one after another in the DOM/HTML. - Initially, to hide the
afterSubmit
element, you added the CSS rule display: none. - You used an onclick event handler function called
switchVisible
to makesurvey
invisible andafterSubmit
visibile. This function performs two actions: a. It changes the display property of thesurvey
from its default valuedisplay: block
todisplay: none
, effectively hiding it. b. It changes the display property of theafterSubmit
element fromdisplay: none
todisplay: block
, making it visible.
you can safely change switchVisible from:
function switchVisible() { if (document.getElementById('survey').style.display == 'none') { } else { document.getElementById('survey').style.display = 'none'; document.getElementById('afterSubmit').style.display = 'block'; } }
where
if (document.getElementById('survey').style.display == 'none') {}
is redundant becausesurvey
IS visible if you are able to see the survey and the submit buttonto (removing the redundant if statement):
function switchVisible() { document.getElementById('survey').style.display = 'none'; document.getElementById('afterSubmit').style.display = 'block'; }
if (document.getElementById('survey')) <-- this equals to true, so it runs the next if/else statement within its block.
Yes! you are on the right track!
When encountering an if statement, the condition inside the parentheses is evaluated. In this case, document.getElementById('survey') retrieves the HTML element with the ID
survey
. If the element exists, it is considered a 'truthy' value, and JavaScript coerces it to true. If the element does not exist (i.e., it is null), it is considered a 'falsy' value, and JavaScript coerces it to false.The if statement does not automatically run again after the page loads unless explicitly triggered by an event or condition.
Please let me now if what I'm saying is wrong, and also what are potential other ways to approach this?
- You can use a
.hidden
utility class and add/remove it on an element usingdocument.getElementById('myElement').classList.add('myClass')
ordocument.getElementById('myElement').classList.remove('myClass')
classList property MDN (BTW classList can help you add a .selected class on the clicked rating!)
.hidden { display: none; }
- Rather than using inline onclick handlers, you can attach event listeners to the submit button using JavaScript. This allows for more flexibility and separation of concerns.
Marked as helpful - You have two articles,
- @naiiiden@diaasaur
Hey nanc =) really enjoyed the transitions you added for adding/deleting todos! I noticed that when I remove the last todo, empty list SVG becomes visible before todo transitions out. Is there a way to delay showing the SVG until the transition is fully completed?
- @naiiiden@diaasaur
Hi nanc!
I found a small bug in years, months days. Steps to reproduce:
- Give input day
19
month2
year2002
- Result is,
21 years 2 months -13 days
instead of21 years 1 months 18 days
Apart from that your solution looks nice and clean ✨ and love that you took care of all the edge cases for form validation!
- Give input day
- @dalinec@diaasaur
Hey Matej, good job on completing your first challenge!
You can make the button look cleaner by:
- Making the icon and text center aligned(vertical + horizontal) and adding a little more gap between them. Like this:
display: flex; justify-content: center; align-items: center; gap: 0.5em;
- Applying the specified font-family and increasing the font size.
Marked as helpful