Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 2 years ago

using first time JavaScript

Enis67•140
@Enis67
A solution to the Interactive rating component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


please help me im loosing hope to becoming a frontend developer

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Riley•260
    @rileydevdzn
    Posted about 2 years ago

    Hi @Enis67

    You did so many things well on this project, don’t give up!

    You did a great job using semantic HTML elements including main and h1 👏, you recognized the rating options as a list (nicely done!), you’re following good practices resetting defaults, using global variables on the root, and keeping specificity low AND you’re employing Flexbox for responsiveness in your CSS, AND you recognized elements you needed to manipulate, you iterated through a list, AND used JavaScript to make your component interactive displaying a new message on clicking the submit button. That is a lot! 🙌

    One of the most important skills a front-end developer needs is problem-solving. The ability to look at a problem, break it down into individual pieces and then put those pieces back together to create a solution. It is paramount to being a good developer, and that is exactly what you’re doing so keep it up! The tools and the frameworks and all the rest will come. And know that you are not alone, we all struggle with this. (The top photo in that article is exactly how I feel sometimes too)

    Here are a few suggestions for your code:

    In the html, if you scroll to the bottom you’ll see some commented out sections (Rating state end, thank-you state start/end) from the starter file. Think of these as hints toward one way of solving this.

    In your code, you’re using a single card and dynamically updating the content items inside the card. This is one way to solve it. My suggestions are for another way to solve it, that you might find slightly easier when it comes to manipulating the JS.

    Another way to do this is to create 2 separate divs for the card that we show at different times. At first, we’d see 1 div with the initial content (How did we do, ratings, submit button) - I’ll call that the ‘rating-div’. And after clicking the submit button, we’d see a 2nd div with the thank-you content (thanks message, image, you selected x of 5 rating), I’ll call that the ‘thankyou-div’. That’s what those commented-out sections in the starter file were alluding to.

    • See if you can create a new ‘thankyou-div’ in the “thank you state start/end” portion of the html file that includes all of the thank-you content. Essentially you’re creating two “faces” of the card that we’ll show to a user. Or if you want to think of them as 2 cards (like a card-flip), whatever works for you.

    • After you’ve created the thankyou-div, now we need to put this div on the page, where it takes up the exact same position and size as the rating-div. Essentially we’re stacking the thank-you div on top of the rating-div.

    • By creating a second thankyou-div, we can keep the content of this div static (creating it in HTML and styling in CSS so you can remove those content items from JS) instead of updating all of the content dynamically. (We do still have to update the ‘you selected x of 5’ later). And once we have the thankyou-div positioned (stacked on top of the rating div), now we need to figure out how to display this div.

    Obviously we want to see the rating-div when we first load the page, so we need to make the thankyou-div invisible at first, and then show after a user clicks the submit button. We have 2 primary properties for visibility: display and visibility. We want to make sure the thankyou-div is invisible both visually and to screen readers so it doesn’t confuse anyone.

    • Ok so we’ve got the thankyou-div create, positioned, and invisible at first. Now how do we show it? There are a number of ways to do this, but I’ll point you toward a JS tutorial that manipulates styling using CSS classes since it’s a pretty straightforward option.

    I’m impressed with the solution you came up with and you’ve hit on all of the concepts you need in your code. The reason I’m suggesting this alternate approach is because it moves the content creation into HTML and styling into CSS so you’re not adding and styling elements from JS. You can add/style from JS and it works to do some things (like dynamic updates of a line), but for the majority of your content it’s better practice to keep the structure (HTML), style (CSS), and interactivity (JS) separate, also makes it easier to debug, update, and maintain in the long run.

    I’ll stop there because this answer is already super long, but try that out. On that website you’ll also find tutorials for lots of other common tasks including manipulating elements (like iterating over elements - which you already did - and manipulating the HTML of an element). If you have any questions or want to go over the next steps, let me know. Coding is hard and you are doing awesome, so keep going! You've got this. 😊 🙌

    Hope this helps and happy coding!

Join 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
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub