I'm using Jquery to calculate the totals of the inputs for this carpet calculator I'm writing. The problem I'm experiencing is being able to output the values while I'm in the for loop but getting NaN when I am outside of both loops as seen below.
Here's a working example of the problem I'm experiencing as well -
https://codepen.io/CodeHero1/pen/abdjpgL
$('#calculate-cost').on('click',function(){
var widthTotalFeet = $('.room-width-feet').map((_,el) => el.value).get();
var widthTotalInches = $('.room-width-inches').map((_,el) => el.value).get();
var roomWidthTotalFeet = 0; // total feet
var roomWidthTotalInches = 0; // total inches
for(var i = 0; i < widthTotalFeet.length; i++) {
roomWidthTotalFeet += parseInt(widthTotalFeet[i]);
console.log('in array');
//This increments correctly
console.log('feet +' + roomWidthTotalFeet);
}
for(var i = 0; i < widthTotalInches.length; i++) {
roomWidthTotalInches += parseInt(widthTotalInches[i]);
//This increments correctly
console.log('inches +' + roomWidthTotalInches);
}
var roomFeetAndInches = parseFloat(roomWidthTotalFeet + '.' + roomWidthTotalInches);
//Receiving NaN on these console logs
console.log('Parse ' + roomFeetAndInches);
console.log('room widht feet=' + roomWidthTotalFeet);
console.log('room widht inches=' + roomWidthTotalInches);
});