I need help creating a website (mainly the JavaScript part of it)

So, the website that I’m trying to create is a calculator that calculates the cost of carpet in a room. It needs to have 2 input boxes, for input length and input width and, when inputted it runs a function to times the length and width together, (to calculate area) and times that by three (to get total cost of carpeting the room). But here comes the tricky part, it needs to be able to add multiple rooms of carpet together to create a new total cost.
Sorry if this is too easy, or not what I’m meant to be posting on a site like this, I’m very new to all of this.
Any and all help would be greatly appreciated! :grinning:

Here’s the Codebyte that you said I should do @vincentb.e , this is the code that I have, but I want to do it in input boxes created in html rather than in JavaScript alerts, and I don’t know how to do multiple rooms.

var length = prompt("Enter a whole number for the length of your rectangle."); var width = prompt("Enter a whole number for the width of your rectangle."); function area(length, width) { return length * width; } document.writeln('The area of your rectangle is ' + area(length, width));

Hi @maucus2532586400
This is definitely the site to be posting questions about development - all we do here is program and develop, even if it’s silly things just created for our own pleasure! :grinning_face_with_smiling_eyes:

Do you have any code so far? If so, could you post it? Oh and remember to create a Codebyte to put it in, otherwise it looks really weird and is hard to read.

So as I see it, there’s two parts to this.
One is creating a <form>, which you can read about here.
The other is retrieving this data, which you can read about here.
As for the multiple rooms, you could first create a form to ask how many rooms there is, then use the concept of replacing a HTML element with another which you can read about here.
This would allow you to specify how many times the form with width and length of a room should be displayed.
There might be a better solution to this, but this is what came off the top of my mind.

1 Like

You can add all the areas to an array. Then calculate the total area and cost from this array (the array method reduce is good for this). If you keep with the prompt method for input, you could use a do or while loop to keep asking for inputs. Later on, you can change the input to use a form and some kind of Add-Room button. Example of keep asking for inputs as long as some inputs are given (modify as needed):

let length, width;
do {
  length = prompt('Enter Length');
  width = prompt('Enter Width');
  // calculate area and push to array
} while (length && width);
1 Like

Start by getting the data from a form, then work your way towards multiple rooms!

This is also a good solution