0
0
Vueframework~20 mins

v-model with radio buttons in Vue - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Radio Button Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1: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>
A"B"
B"A"
Cundefined
Dnull
Attempts:
2 left
💡 Hint
Remember that v-model binds the value of the selected radio button to the variable.
📝 Syntax
intermediate
1: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.
A<input type="radio" v-model="choice" value="1" />
B<input type="radio" value="1" v-model="choice" />
C<input v-model="choice" type="radio" value="1" />
D<input type="radio" value="1" :v-model="choice" />
Attempts:
2 left
💡 Hint
The order of attributes does not affect functionality, but the syntax must be correct.
state_output
advanced
2: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>
A"C"
B"B"
C"A"
Dnull
Attempts:
2 left
💡 Hint
Each radio button click updates the selected value to that button's value.
🔧 Debug
advanced
2: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>
AThe <code>id</code> attributes must be unique strings without numbers.
BThe use of <code>:v-model</code> is incorrect; it should be <code>v-model</code> without a colon.
CThe <code>selected</code> variable must be declared with <code>reactive</code> instead of <code>ref</code>.
DThe <code>value</code> attributes must be numbers, not strings.
Attempts:
2 left
💡 Hint
Check the syntax of the v-model directive.
🧠 Conceptual
expert
2: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?
AOnly the first radio button with that value can be selected; others are disabled.
BVue throws a runtime error because radio buttons must have unique values.
CThe <code>v-model</code> variable becomes an array of all selected values.
DSelecting any radio button sets the <code>v-model</code> variable to that shared value; the buttons behave as one group.
Attempts:
2 left
💡 Hint
Think about how radio buttons work in HTML and how v-model binds to their value.