Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to make a grocery list in javascript

<!DOCTYPE html>
<html>
<head>
<script>
function getit(){
    var result = document.getElementById('demo');
        var allitems = 0;
            var itemCount = prompt("how many items do you need?");
                var items = {};
for (i = 0; i < itemCount; i++) {
items[i] = {

    name : prompt("Product Name"), 
    price : prompt("Product Price"), 
    qty : prompt("Product qty")

    }
}

for (i = 0; i < itemCount; i++) {
var subtotal = 0;
var total = 0;
subtotal = items[i].price * items[i].qty;
total = subtotal * 1.05;
allitems = allitems + subtotal; 
result.innerHTML += "Product: " + items[i].name + "<br/>";
result.innerHTML += "Total Qty: " +items[i].qty + "<br/>";
result.innerHTML += "Sub total: " + subtotal + "<br/>";
result.innerHTML += "Sub total: " + total + "<br/>";
if(i == (itemCount - 1)){result.innerHTML += "Sub total for all items: " + allitems + "<br/>";}
}
    }
</script>
    </head>
<body>
<button onclick="getit()">Shop</button>
<p id="result">Creating a JavaScript Object.</p>



</body>
</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: get user agent in js 
Javascript :: unix timestamp js 
Javascript :: logic operators in js 
Javascript :: javascript check if visible 
Javascript :: axios post request 
Javascript :: upi id regex 
Javascript :: how to export multiple functions react from one file 
Javascript :: axios data fetch 
Javascript :: fetch json data into array 
Javascript :: javascript function to strikethrough text 
Javascript :: Substring in Javascript using substring 
Javascript :: Adding a Method to a JavaScript Object 
Javascript :: counting duplicate values javascript 
Javascript :: how to pass a prop in route 
Javascript :: incoroporate js and css file in html 
Javascript :: Nestjs download 
Javascript :: get param from url jquery 
Javascript :: fs fstat 
Javascript :: index of 
Javascript :: javascript read consol input 
Javascript :: js substr 
Javascript :: js object entries 
Javascript :: mongoose count 
Javascript :: Reduce array to a single string using reduce 
Javascript :: gsap scrolltrigger 
Javascript :: cache request in vue 
Javascript :: global axios vue 2 
Javascript :: vuejs set default value for prop 
Javascript :: how to comment out code in react js 
Javascript :: usb react native device not found 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =