Challenge - 5 Problems
Computed State Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Vue computed property?
Consider this Vue component using the Composition API. What will be displayed inside the paragraph when the component renders?
Vue
<script setup> import { ref, computed } from 'vue' const count = ref(3) const doubleCount = computed(() => count.value * 2) </script> <template> <p>{{ doubleCount }}</p> </template>
Attempts:
2 left
💡 Hint
Remember that computed properties return a reactive value based on other reactive sources.
✗ Incorrect
The computed property doubleCount multiplies count.value (3) by 2, resulting in 6. This value is displayed in the paragraph.
❓ state_output
intermediate2:00remaining
What is the value of fullName computed property?
Given this Vue component, what is the value of the computed property fullName?
Vue
<script setup> import { reactive, computed } from 'vue' const user = reactive({ firstName: 'Jane', lastName: 'Doe' }) const fullName = computed(() => `${user.firstName} ${user.lastName}`) </script>
Attempts:
2 left
💡 Hint
Look at the template literal combining firstName and lastName with a space.
✗ Incorrect
The computed property fullName concatenates user.firstName and user.lastName with a space, resulting in "Jane Doe".
📝 Syntax
advanced2:00remaining
Which option correctly defines a computed property that returns the square of a number?
Select the option that correctly defines a computed property named squared that returns the square of a reactive number value.
Attempts:
2 left
💡 Hint
Remember to access the reactive value with .value and use the exponentiation operator.
✗ Incorrect
Option D correctly accesses number.value and uses the exponentiation operator ** to square it. Option D and C multiply by 2 instead of squaring. Option D uses ^ which is a bitwise XOR, not exponentiation.
🔧 Debug
advanced2:00remaining
Why does this computed property not update when the reactive source changes?
Given this Vue component, why does the computed property fullName not update when user.firstName changes?
Vue
<script setup> import { reactive, computed } from 'vue' const user = { firstName: 'John', lastName: 'Smith' } const fullName = computed(() => `${user.firstName} ${user.lastName}`) user.firstName = 'Mike' </script>
Attempts:
2 left
💡 Hint
Check how user is declared and whether Vue can track its changes.
✗ Incorrect
The user object is a plain object, not reactive. Vue cannot track changes to its properties, so fullName does not update when firstName changes.
🧠 Conceptual
expert2:00remaining
How does Vue's computed property caching work?
Which statement best describes how Vue caches computed properties?
Attempts:
2 left
💡 Hint
Think about efficiency and when Vue should update computed values.
✗ Incorrect
Vue tracks reactive dependencies of computed properties and only recalculates them when those dependencies change, improving performance.