Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Tadjiev Codes
Tadjiev Codes
9,626 Points

JS DOM issues with the Code and reset buttons

Hi guys, hope all is going well) Can somebody help me pls to debug and find the solution for my issues?

1) How to reset the total amount in JS and total Tax amount? I can reset now the quantity because of the DOM querySelectorAll and then set to 0 But the rest can't understand yet.

2) I added 4 variables with the description of the items. But now how to show those descriptive names of the items once 2 burgers have been selected let's say? For me now it only shows the amount 15.99$ but not the name even I tried adding variable names to the output and then removed. So I want it to show Burger meal Option 3 and the price of it 17.99$

The link of the snapshot of my workspace: https://w.trhou.se/jo0r9wdywo

Really appreciate your help with this))))

Steven Parker
Steven Parker
229,645 Points

You can't share a direct URL to your workspace, it's temporary and only exists while you are using it.
But you can use the snapshot function in the workspace to create a persistent link and provide that.

Tadjiev Codes
Tadjiev Codes
9,626 Points

I updated the post with a snapshot of Treehouse. Thanks)

2 Answers

Steven Parker
Steven Parker
229,645 Points

Resetting the orders is even easier than clearing the counters, just add this to "MyResetFunction":

            a = b = c = i = totalOrders = mealQuantity = 0;  // clear all the variables
            calculating();    // then recalculate and display 0

Then, to display a list of choices you might add a new space to the HTML:

    <div id="itemsList"></div>   <!-- new space -->
    <div style="color: black; font-weight: bold; padding: 5px;" id="theOutputArea">  <!-- existing space -->

And add a line to it for each button click:

        function buttonClick1() {
//          ... (existing code) ...
            document.getElementById("itemsList").innerHTML += "Soup $" + mealOption1 + "<br>";
        }

But how far have you gone in the JavaScript courses? Perhaps you're getting ahead of things and all this will become easier once you've gone a bit farther with your training.

Tadjiev Codes
Tadjiev Codes
9,626 Points

Hi, Mr.Steven) Thank you soo much for helping me out with this. I do really appreciate it. And, the strings you have created like "Soup $", I've actually replaced it with the same-named variables so it's not kinda hardcoded. But your solution really works Cool. I love it) My story is a bit complicated. I got inspired to learn how to code in June 2018 because of my friend who subscribed to Treehouse and shared the downloaded videos with me for HTML and CSS basics. And, then I've become a Member Since August 25, 2018, but with lots of pauses as It was really challenging to find a coding junior well-paid job in Dubai. So i was always hesitating whether that's for me. I'm not good at Math and there are no chances for juniors where I live. I wasn't able just to give up my another job and work for free as a junior. Then, I decided to come to Canada and take a 2 yeat Web development program at one College. And, luckily I'm here now. This is how far I guess coding brought me) I watched all the basic JS courses at Treehouse, Jonas UDemy JS, WEsbos JS basics which I didn't complete yet. But mostly without much of practice. So when I started to encounter real examples , small projects like this, that's where it gets hard for me to think programmatically and solve the problems. And, I find the treehouse and online resources much easier to comprehend than my lectures. Because I could pause stop and watch it again even if it sounds a little stupid .But I'm here at the College since January and trying to dedicate all my time 7 to 8 hours a day least to learn something new. So I really hope that from my summer semester I could find at least a Junior front end Web Developer's job. Do you really think math is important for web development? It's quite challenging for me to work with math operations although i understood conversion binary to decimal and vice versa. However converting IP addresses to network addresses ors subnet masks. That seems really hard for me. Do i really need to know how to convert IPs manually by math? Thanksa lot for your support ))))))))))))))))))))))))

Steven Parker
Steven Parker
229,645 Points

Math skills are helpful, but with the ready availability of sophisticated calculators (including online apps) it's not as essential as in the past. Best of luck with your studies, and happy coding!