Hey

Dean here again, I've been assigned to make an earnings calculator with user input I'm just having trouble in making the final sum work I just get NaN for an answer

``````function getValue() {

var values = new Array(239.99, 129.75, 99.95, 350.89);
var name = prompt("Enter your name: ","name here");
var quan1 = prompt("How many of item 1 were sold : ","Quanity sold");
var quan2 = prompt("How many of item 2 were sold : ","Quanity sold");
var quan3 = prompt("How many of item 3 were sold : ","Quanity sold");
var quan4 = prompt("How many of item 4 were sold : ","Quanity sold");
var com1 = alert("Your commission on item 1 is : " + Math.round(((values * quan1) * 0.09) * 100) / 100);
var com2 = alert("Your commission on item 2 is : " + Math.round(((values * quan2) * 0.09) * 100) / 100);
var com3 = alert("Your commission on item 3 is : " + Math.round(((values * quan3) * 0.09) * 100) / 100);
var com4 = alert("Your commission on item 4 is : " + Math.round(((values * quan4) * 0.09) * 100) / 100);
alert("Total earnings for the week for: " + name + (parseFloat(com1) + parseFloat(com2) + parseFloat(com3) + parseFloat(com4) + 200) );
}``````

Any help will be appreciated

Thanks

Dean

your current com1 -> com4 values are strings, not numbers, therefore NaN.
set your numbers in separate variables, then you can work with them later.

``````function getValue() {

var values = new Array(239.99, 129.75, 99.95, 350.89);
var name = prompt("Enter your name: ","name here");
var quan1 = …``````

## All 2 Replies

your current com1 -> com4 values are strings, not numbers, therefore NaN.
set your numbers in separate variables, then you can work with them later.

``````function getValue() {

var values = new Array(239.99, 129.75, 99.95, 350.89);
var name = prompt("Enter your name: ","name here");
var quan1 = prompt("How many of item 1 were sold : ","Quanity sold");
var quan2 = prompt("How many of item 2 were sold : ","Quanity sold");
var quan3 = prompt("How many of item 3 were sold : ","Quanity sold");
var quan4 = prompt("How many of item 4 were sold : ","Quanity sold");
var com1 = Math.round((((values * quan1) * 0.09) * 100) / 100);
var com2 = Math.round((((values * quan2) * 0.09) * 100) / 100);
var com3 = Math.round((((values * quan3) * 0.09) * 100) / 100);
var com4 = Math.round((((values * quan4) * 0.09) * 100) / 100);