-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User can choose spell to cast #3
Comments
You can add a select element in the import React, { useState } from 'react';
import './App.css';
function App() {
// Declare state variable for selected spell
const [spell, setSpell] = useState('');
// Event handler for when user selects a spell
const handleSpellChange = (event) => {
setSpell(event.target.value);
};
// Event handler for when user clicks "Cast Spell" button
const handleCastSpell = () => {
// Cast the selected spell
console.log(`Casting ${spell}`);
};
// Render the component
return (
<div className="App">
<h1>Spell Caster</h1>
<label htmlFor="spell-select">Choose a spell:</label>
<select id="spell-select" value={spell} onChange={handleSpellChange}>
<option value="">Select a spell</option>
<option value="fireball">Fireball</option>
<option value="frostbolt">Frostbolt</option>
<option value="arcane-missiles">Arcane Missiles</option>
</select>
<button onClick={handleCastSpell}>Cast Spell</button>
</div>
);
}
export default App; Created a Also created a |
No description provided.
The text was updated successfully, but these errors were encountered: