Design comparison
Solution retrospective
- I think the toggle button got a bit of issue. If i click on the button and drag along in the blue area, the round white button could end up not moving, and yet the Javascript will run and change the price from monthly to Annual price.
- Does anymore really use the font size 15px (or in rem) for any text in the challenge? It seems a little small to me compare to the design pic.
- and the ::first-letter, i think it impacted the position of the price when the event runs (when i toggle the button). If i chose to preserve the ::first-letter in my CSS, is there anyway to solve the problem on the position of the price?
- I think my JS is a bit necessary complicated. I vaguely remember on an easier way to do it but i can't remember the source. Can anyone judge my JS?
- If anyone capable on ONLY using HTML and CSS to solve this problem, please, enlighten me.
- I used like 7 to 8 hours to solve this problem (including the time on researching on how to solve various problems), is it normal?
Community feedback
- @elaineleungPosted about 2 years ago
Hi Jetyun, great work here, and great questions as well. I also completed this challenge recently, so I'm quite familiar with some of the hurdles involved here. Anyway, I don't know whether I can answer all these questions, but I'll try!
-
The toggle button works fine for me when I click on the empty area to switch states, and I can't see anything in your CSS or JS that makes it dragable. It's also a checkbox, which means that its state is changed through clicking and that no matter where you click in the area, as long as clicking happens, the toggling should happen. I think the only two things I'd change here is the width of the div (maybe 300px), as things look super squished right now, and I'd also add
cursor:pointer
to the slider. -
I used 15px (or 0.9375 rem in my case) for the body text.
-
Instead of using
::first-letter
, can you try using a<span>
tag for the dollar sign and then changing the font-size in the CSS with the span? That's what I did in my solution! -
Yes, the JS can be simplified! Just using what you have here instead of writing something new: Since you're using a conditional statement instead of an event listener, you can try using the checkbox state for evaluation instead of the three elements, where
true
means annual is checked, andfalse
means monthly is checked. Instead of writing 6 lines of inline styles, you can try removing/adding a class on the parent of the 6 elements (in this case, I'd choose the grid as the parent element), and that class would change the styles. I haven't tested this, just basing on theory and past experience, so I do apologize if things get switched around, but anyway it looks like this:// JS const checkboxEl = document.querySelector("[type=checkbox]") const gridEl = document.querySelector(".grid") function changeprice(){ if (checkboxEl.checked) { gridEl.classList.add("is-checked") } else { gridEl.classList.remove("is-checked") } } // CSS: .annual { display: none; } .is-checked .annual { display: inline-block; } .monthly { display: inline-block; } .is-checked .monthly { display: none; }
-
I actually did it without any JS; it just involved a careful placement of where the
input
elements need to be in order for them to affect the styling of other selectors. Solution is here if you're interested! -
Yes, this is normal in my experience, and I've heard of experienced developers doing similar things, just with more complex tasks. It gets faster though once you get good with the problem solving!
Marked as helpful0 -
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord