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
Samuel Glister
12,471 PointsJavaScript Equation Problems
Hi All,
Being a bit of a newbie to Javascript i'm having a few issues trying to get an equation to work on a program I am trying to create.
Based on what the user inputs into a input field I want it to do the following
((userValue/3)*4) - where userValue = whatever is entered into the input field.
I have tried the following code which doesn't appear to return the results I wanted
var in_value1 = document.getElementById('in-value1').value;
document.getElementById('in-result2').innerHTML = (parseInt(in_value1) * parseInt(2.54)) / parseInt(100);
Any help would be appreciated.
Thank you
1 Answer
jobbol
Full Stack JavaScript Techdegree Student 19,117 PointsYou want:
(userValue/3)*4
but your code is:
(userValue*2.54)/100
So just change the code.
http://jsfiddle.net/xo3yeyu1/2/
Additionally, you don't need to use parseInt all over the place. Javascript will convert strings to integers for you.