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 trialXu Cheng
5,038 PointsTotal Price doesn't show up properly /
I am trying to do Javascript Techdegree Project 3 right now. I got stuck at "”Register for Activities” section of the form:" part. The price is not showing up correctly. For example, when I checked main, the price shows up in the end is $100 (while it is supposed to be $200), when I unchecked it, it became -$100 .... When I click others it stays at $0. I tried to use console.log to test and it seems like the calculation within the if statement is fine but it is not correctly pass to the end of the function so my innerHTML part doesn't work correctly.
Anyone knows why exactly and how should I change it? Thanks
The requirement for that part is "As a user selects activities, a running total should display below the list of checkboxes. For example, if the user selects "Main Conference", then Total: $200 should appear. If they add 1 workshop, the total should change to Total: $300."
My code is : https://github.com/xu0224/Build-an-Interactive-Form
Xu Cheng
5,038 PointsQuestion updated, github link attached!
1 Answer
Steven Parker
231,269 PointsI see a few logic issues.
In your activities change event handler, you have two if...else chains. In the second one you subtract amounts from the total, but you don't need this because in the first one you start the total with zero and only add an amount if the item is checked. So you can eliminate that second chain entirely.
But in the first chain, you don't want else if because that will cause it to respond to only the first item checked. To be able to respond to each item and produce a sum you should just have plain if statements and evaluate each checkbox independently.
Steven Parker
231,269 PointsSteven Parker
231,269 PointsIt looks like the HTML component would be needed to test this.
Also, be sure to format shared code using the Markdown Cheatsheet link at the bottom of the "Add an Answer" section.
Even better, make a snapshot of your workspace and post the link to it here to share all modules at once.