Challenge - 5 Problems
Radio Button Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What is the value of
selected after selecting the second radio button?Consider this Vue 3 component using
v-model with radio buttons. What will be the value of selected after the user clicks the second radio button labeled 'Option B'?Vue
<template>
<div>
<input type="radio" id="optA" value="A" v-model="selected" />
<label for="optA">Option A</label>
<input type="radio" id="optB" value="B" v-model="selected" />
<label for="optB">Option B</label>
</div>
</template>
<script setup>
import { ref } from 'vue'
const selected = ref('A')
</script>Attempts:
2 left
💡 Hint
Remember that
v-model binds the value of the selected radio button to the variable.✗ Incorrect
When the user clicks the radio button with value "B", v-model updates the selected variable to "B".
📝 Syntax
intermediate1:30remaining
Which option correctly binds
v-model to a radio button group?Select the code snippet that correctly uses
v-model with radio buttons in Vue 3.Attempts:
2 left
💡 Hint
The order of attributes does not affect functionality, but the syntax must be correct.
✗ Incorrect
All options except D use correct syntax. However, :v-model is invalid. Options A, B, and C are valid, but only A is the canonical recommended order.
❓ state_output
advanced2:00remaining
What is the value of
selected after this sequence of user actions?Given this Vue 3 component, the user first selects 'Option C', then selects 'Option A'. What is the final value of
selected?Vue
<template>
<div>
<input type="radio" id="optA" value="A" v-model="selected" />
<label for="optA">Option A</label>
<input type="radio" id="optB" value="B" v-model="selected" />
<label for="optB">Option B</label>
<input type="radio" id="optC" value="C" v-model="selected" />
<label for="optC">Option C</label>
</div>
</template>
<script setup>
import { ref } from 'vue'
const selected = ref('B')
</script>Attempts:
2 left
💡 Hint
Each radio button click updates the
selected value to that button's value.✗ Incorrect
Initially, selected is "B". Selecting 'Option C' changes it to "C". Then selecting 'Option C' changes it to "A".
🔧 Debug
advanced2:00remaining
Why does this Vue 3 radio button group not update the
selected value?Examine this code. The radio buttons appear, but clicking them does not change the
selected value. What is the cause?Vue
<template>
<div>
<input type="radio" id="opt1" value="1" :v-model="selected" />
<label for="opt1">One</label>
<input type="radio" id="opt2" value="2" :v-model="selected" />
<label for="opt2">Two</label>
</div>
</template>
<script setup>
import { ref } from 'vue'
const selected = ref('1')
</script>Attempts:
2 left
💡 Hint
Check the syntax of the
v-model directive.✗ Incorrect
Using :v-model treats v-model as a dynamic prop binding, which is invalid. It should be v-model without a colon.
🧠 Conceptual
expert2:30remaining
What happens if multiple radio buttons share the same
value but different id attributes with v-model?In Vue 3, if you have multiple radio buttons with the same
value but different id attributes all bound to the same v-model variable, what is the expected behavior when a user selects any of these buttons?Attempts:
2 left
💡 Hint
Think about how radio buttons work in HTML and how
v-model binds to their value.✗ Incorrect
Radio buttons with the same name (or bound by v-model) act as a group. If multiple have the same value, selecting any sets the model to that value. No error occurs.