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

Pass Javascript var on to html alertbox? (alert calculated result based on user input?)

I have only completed the apprentice program, but I have been doing lots of research on how to make a recipe calculator used in Black Desert Online. I hope I've annotated my comments well, I just used the shell page as far as CSS that came with my apprenticeship project.

Basically, every ingredient has an associated weight and players are limited to how much total weight they can carry. Players can only make beer if there weight reaches 99% at a max. So, if a player that weighs 504 wants to carry the most ingredients possible (whole number without rounding), he or she would be capped at 498 pounds worth of ingredients.

Therefore, I am trying to develop a calculator that lets a user know how much beer can be made in a single trip (from the stovetop to the bank and back)

Ideally, I wanted it to say the ingredient amounts needed but that was gonna require even more advance skills I currently have, but its work in progress.

Also if you have any code advice, please let me know as I am new.

Here is my link: https://w.trhou.se/8iimcrer86

2 Answers

Steven Parker
Steven Parker
231,153 Points

I don't know what's in the apprentice program, but it looks like you might benefit from a few supplemental courses, if they allow you to take others from the library and/or tracks. The Front End Web Development track in particular might be useful.

But here are a few pointers:

  • it's not good practice to have JavaScript code both in a separate file and inside the HTML
  • the "button.js" file isn't currently being loaded by the HTML
  • a JavaScript file should not contain any HTML code
  • the code in "button.js" attempts to reference an HTML element with id "mytext" (that does not exist)

Once you get the structure issues worked out, it's easy to display your calculated results in an "alert" just by concatenating a variable with the output string.

Thanks, I don't know if I have access but I'll look into it.