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

I know I am missing something stupid here.

if you type in 115 in the sq feet text box and 30 in the gallon text box the total is 190 which is correct however if you change the sq feet to 116 it should display 221.39, because you can not buy 1.0087 gallons of paint so you have to round it up to two gallons and multiply that by the cost per gallon. JavaScript

//Paint Job Estimator
let isqft = document.querySelector('input[name="sqft"]');
let igallon = document.querySelector('input[name="gallon"]');
let disp18 = document.querySelector('p#dis18');
let tsqft = 0, tgallon = 0, total18 = 0, totgal = 1;
document.addEventListener('click', r => {
    if (r.target.tagName="BUTTON") switch(r.target.id){
        case 'calc18' : tsqft = parseInt(isqft.value); tgallon = parseInt(igallon.value); totgal = tsqft/115; Math.ceil(totgal);
        totgal *= tgallon; total18 = (tsqft/115) * 160 + totgal; disp18.innerHTML = "Your total comes to $" + total18.toFixed(2); break;
        case 'clear18' : isqft.value = igallon.value = disp18.innerHTML = '';
    }
});

HTML

<div class="all" id="pro18"><!-- Paint Job Estimator -->
                <h1>Paint Job Estimator</h1>
                <form>
                    <label for="sqft">How many square feet:</label>
                    <input type="text" name="sqft" id="sqft"><br>
                    <label for="gallon">Paint cost per gallon:</label>
                    <input type="text" name="gallon" id="gallon"><br>
                    <button type="button" id="calc18">Calculate</button>
                    <button type="button" id="clear18">Clear</button>
                </form>
                <p id="dis18"></p>
            </div>

2 Answers

Steven Parker
Steven Parker
243,318 Points

If you write the expression "Math.ceil(totgal);" as a stand-alone statement, it computes the ceiling value but it does not save it anywhere.

You probably want "totgal = Math.ceil(totgal);" instead.

the man the myth the legend. Thanks again Steven.