You're building an age categorization app and want to display the category based on the user's input age. The below Vue application uses an input field for age. Use a watcher to display an age category based on the input value (e.g., "Child," "Teen," "Adult").
Watching for changes
Age categorization
Report a typo
Fill in the gaps with the relevant elements
<template>
<div>
<label>Enter your age:</label>
<input v-model="age" type="number" />
<p>Your age category is: {{ ageCategory }}</p>
</div>
</template>
<script setup>
import { ref, watch } from 'vue'
const age = ref(0)
let ageCategory = ''
(, () => {
if (newAge < 18) {
ageCategory = 'Child'
} else if (newAge < 40) {
ageCategory = 'Teen'
} else {
ageCategory = 'Adult'
}
})
</script>Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.