Husky653 - 11 months ago 37

HTML Question

I have to make a form where the costumer can enter quantity, orderdate and delivery and then by clicking a button he will get his price.

Now the price depends on the quantity and order date.

He gets a discount of 2.5% if he orders more than 10 items (

`q > 10`

Now he only gets the discount on the extra items he orders.

If he orders less that 10 then he just pays quantity*341, where 341 is the price of one item.

I managed to do this part and get a result, but then I have to expand the function such that if he orders Monday, Tuesday and Wednesday then he gets a discount of 5%.. I tried to do this but I always get the result

`NaN`

Here is what I have so far:

`<p>We create a web based interface for calculating the consumers costs. The perception is that it could provide a quick and easy access. The focus of the assignment is the price calculation.</p>`

<p1>Quantity</p1> <!-- Note that the costumers only can choose a positive quantity -->

<p1><input type="number" min="1" id="quantity" name="quantity"></p1>

<p1> </p1>

<p1>Order date</p1> <!-- Note that the costumers only can choose a real date -->

<p1><input type="date" id="oDate" name="oDate"></p1>

<p1> </p1>

<p1>Delivery date</p1> <!-- Note that the costumers only can choose a real date -->

<p1><input type="date" id="dDate" name="dDate"></p1>

<p1> </p1>

<button onclick="myCalc()">Calculate Price </button>

<p id="calculate"></p>

<p>

<script>

function myCalc() {

var q = quantity.value;

var total;

var qDiscount;

var dDiscount;

var oDate = new Date()

var day = oDate.getDay();

var Dday = (day == 1) || (day == 2)|| (day == 3);

if (q > 10) {

qDiscount = (q-10) * 341 * 0.025;

} else {

qDiscount = 0 ;

}

if (Dday) {

dDiscount=q*341*0.05;

} else {

dDiscount==0;

}

total = q * 341 - qDiscount - dDiscount

document.getElementById("calculate").innerHTML = total;

}

</script>

Hope someone can help me, I have been stuck with it for hours now.

Answer Source

```
dDiscount==0;
```

should be

```
dDiscount = 0;
```

Also you missed a semicolon, this:

```
total = q * 341 - qDiscount - dDiscount
```

should be this:

```
total = q * 341 - qDiscount - dDiscount;
```

(your day checking code looks ok...)