I got this feedback from my teacher about my code but i dont know how to fix it
There is an issue with the area, it might be because you do not calculate it until after all the conditionals. Also it should not output with a £.
There is also an issue with the undercoat cost, this might be because you have 2 variables with the same name.
var help = prompt("Do you need any help?");
if (help ==="yes"){
myFunction();
}
else if(help ==="no"){
}
myFunction = function(){
alert("First enter the height of your room into the box");
alert("Enter the first length of your room");
alert("Enter the second length of your room");
alert("Enter the third length of your room");
alert("Enter the fourth length of your room");
alert("Then type in what paint you want your room to be");
alert("Choose is you want undercoat by typing yes or no");
alert("Finally the total cost should appear in your box");
alert("FAQ What happens if I have entered the wrong length... keep pressing cancel and restart");
alert("FAQ What happens if my house has three walls ... type in three lengths and press 0 for the fourth");
alert("FAQ What happens if i want one wall one colour and another wall the other...... At the moment this app cant calculate that");
};
var height = prompt ("Please enter Your Height");
var lengthArray = [];
for ( i = 0 ; i<4; i ++ ){
var length = prompt ("Please enter your lengths");
lengthArray.push(length);
console.log(lengthArray);
var area = height * length;
}
// Paint Cost
var Economy = 0.45;
var Standard = 1.00;
var Luxury = 1.45;
var underCoat = 0.50;
var paintCost;
var undercoatCost;
// The if stament for the standard costs
var paintChoice = prompt (" Please Choose your paint ");
if (paintChoice === "Standard"){
paintCost = (Standard*area);
console.log("The cost of this paint will be " + paintCost);
}
// The if stament for the standard costs
else if (paintChoice === "Economy"){
paintCost = (Economy*area);
console.log("The cost of this paint will be " + paintCost);
}
// The if stament for the standard costs
else if (paintChoice === "Luxury"){
paintCost = (Luxury*area);
console.log("The cost of this paint will be " + paintCost);
}
// This is the else if stament for the choice of selecting a wrong colour
else if (paintChoice === "Red"){
console.log("You have chosen the wrong paint choice ");
}
// This is the the if stament for undercoat when you choose yes
var underCoat = prompt ("Would you like any undercoat? ");
if (underCoat === "Yes"){
undercostCost = (area*underCoat);
console.log("The cost of the undercoat will be " + undercoatCost);
}
// This is the else if statement for undercoat when you choose no
else if (underCoat === "No"){
console.log("You have chosen not to have undercoat ");
}
// This is the variable to total up the lengths
var total = [];
var lengthSum = lengthArray[0] + lengthArray[1] + lengthArray[2] + lengthArray[3];
console.log(lengthSum);
var area = (height*lengthSum);
alert("The area of the room is " + area.toFixed(2));
public static void main(String[] args)
{
}