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 trialJoseph Escobedo
Full Stack JavaScript Techdegree Student 4,172 PointsGetting the price value in Unit 3 project
I'm trying to get the value of each price in the Unit 3 project. I found the index of the dollar sign and now i need to get the number value. The guide says to use slice but I cant figure out how to use it if its now in an array. I tried a for loop, but each time i press a check box it loads all the values for each checkbox. I reduced my code back to where I find the index of the dollar sign.
$(activities).change(e => {
let inputs = $(e.target)
.parent()
.text();
const indexOfDollarSign = inputs.indexOf("$");
console.log(indexOfDollarSign);
});
github js file: https://github.com/joeEscob1023/interactiveForm/blob/master/js/app.js
1 Answer
Steven Parker
229,608 PointsI'm not sure what you mean by "its now in an array". But once you have the index of the currency sign, you can take a slice starting one character beyond that to get to the number. And assuming you want a number, you can then wrap that all in a "parseFloat":
const price = parseFloat(inputs.slice(indexOfDollarSign + 1));
Joseph Escobedo
Full Stack JavaScript Techdegree Student 4,172 PointsJoseph Escobedo
Full Stack JavaScript Techdegree Student 4,172 PointsThank you! I actually meant to say, its not in an array. You've been the best help that I've had while doing this tech degree!
Steven Parker
229,608 PointsSteven Parker
229,608 PointsI'm flattered.   Do you take advantage of the support on "Slack"?
Joseph Escobedo
Full Stack JavaScript Techdegree Student 4,172 PointsJoseph Escobedo
Full Stack JavaScript Techdegree Student 4,172 PointsI do try to use the slack first before I ask on here, but theres not much activity in the unit 3 chat.