Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Coding issue read

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Coding issue read

    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)
    {
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Coding issue read

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers.

    After you fix your post so that your code is posted correctly, describe what you've done to address your teacher's comments.

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Coding issue read

    please can someone help me

  4. #4
    Junior Member
    Join Date
    Jan 2014
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Coding issue read

    so what is the exact problem that you would like to fix? please elaborate it.

Similar Threads

  1. Read Textfile from server, memory issue
    By XxxXxx896 in forum Android Development
    Replies: 7
    Last Post: May 11th, 2013, 06:21 AM
  2. Read Textfile from server, memory issue
    By XxxXxx896 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 11th, 2013, 06:21 AM
  3. Java Issue / Cache issue
    By VisualPK in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 14th, 2012, 08:43 PM
  4. Read input, read file, find match, and output... URGENT HELP!
    By MooseHead in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 3rd, 2012, 11:01 AM
  5. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM