Quiz: Paying
Clicking Pay should thank the customer and say how much they paid, but the page shows Thank you! You paid €[object Object]. Click the line with the mistake.
1<script setup>
2import { computed, ref } from "vue";
3
4const order = ref([
5 { id: 1, name: "Espresso", price: 2, count: 2 },
6 { id: 5, name: "Carrot Cake", price: 4, count: 1 },
7]);
8const message = ref("");
9
10const total = computed(() => {
11 let sum = 0;
12 for (const item of order.value) {
13 sum += item.price * item.count;
14 }
15 return sum;
16});
17
18function pay() {
19 message.value = `Thank you! You paid €${total}.`;
20 order.value = [];
21}
22</script>
23
24<template>
25 <h1>Corner Café</h1>
26 <ul class="order">
27 <li v-for="item in order" :key="item.id">
28 {{ item.count }}× {{ item.name }}
29 </li>
30 </ul>
31 <p>Total: €{{ total }}</p>
32 <button @click="pay">Pay</button>
33 <p class="message">{{ message }}</p>
34</template>