Need help with js and html DIV via /r/learnprogramming

Need help with js and html DIV

I'm really new at this taking a crash course at a community college. The task is to build a base html for a calculator javascript function to run for the price of pizza per sq in. When it comes to trying to attach the results to the html div in order to show the results it results in $NaN. Now instead, it is supposed to show the price per in based on size, price and toppings so you get something like $0.16 once you hit a calculate button. I'll post my code, but please note, it is some ugly stuff but I'd rather just hae it work.

// var pizzaPSI = function(d1, d2, d3){ return(d1 / (((Math.PI) * (Math.pow((d2 / 2), 2))) + ((d3 * 1.25)))); };

var main = function() { var price = Number(document.querySelectorAll("input")[0].value); var size = Number(document.querySelectorAll("input")[1].value); var tops = Number(document.querySelectorAll("input")[2].value); var results = pizzaPSI(price / ((((Math.PI) * (Math.pow((size / 2), 2)))) + (tops * 1.25)));

document.querySelector("div").innerHTML = ("$" + results); 


window.addEventListener("load", function() {

document.querySelector("button").addEventListener("click", main); 

}); //

Submitted July 14, 2017 at 06:02AM by DidntWantAccount
via reddit


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s