Question 2
Consider the following HTML, with the correct Vue 2 CDN links included:
Html code.
<div id="app"> <h3>Shopping Cart</h3> <p>Items: {{itemCount}}</p> <p>Total Cost: ${{totalCost}}</p> <button @click="addItem">Add Item ($15)</button> <button @click="removeItem">Remove Item</button> <p>Status: {{status}}</p></div>script:
const app = new Vue({ el: '#app', data() { return { itemCount: 0, itemPrice: 15, totalCost: 0 } }, computed: { status() { if (this.itemCount === 0) { return 'Empty Cart'; } else if (this.itemCount < 3) { return 'Few Items'; } else { return 'Full Cart';
} } }, methods: { addItem() { this.itemCount++; this.totalCost += this.itemPrice; }, removeItem() { if (this.itemCount > 0) { this.itemCount--; this.totalCost -= this.itemPrice; } } }})If the user clicks the "Add Item" button 3 times, then clicks the "Remove Item" button 1 time, what will be displayed for Items, Total Cost, and Status?
Items: 2, Total Cost: $30, Status: Few Items
Items: 2, Total Cost: $45, Status: Few Items
Items: 3, Total Cost: $30, Status: Full Cart
Items: 2, Total Cost: $30, Status: Full Cart
Items: 1, Total Cost: $15, Status: Few Items