Skip to content

Instantly share code, notes, and snippets.

@slightlyoffbeat
Last active February 9, 2022 00:01
Show Gist options
  • Save slightlyoffbeat/93bf845478b5140274ca7ae15a47229b to your computer and use it in GitHub Desktop.
Save slightlyoffbeat/93bf845478b5140274ca7ae15a47229b to your computer and use it in GitHub Desktop.
Boyband Name Generator
export const boybandData = {
zodiac: {
Aries: ['Boyz'],
Taurus: ['Lads'],
Gemini: ['Town'],
Cancer: ['Luv'],
Leo: ['Street'],
Virgo: ['Squad'],
Libra: ['Bros'],
Scorpio: ['Union'],
Sagittarius: ['Bunch'],
Capricorn: ['Crush'],
Aquarius: ['Republic'],
Pisces: ['Budz']
},
initial: {
a: ['Beat'],
b: ['CrayCray'],
c: ['Macho'],
d: ['Boom'],
e: ['Swing'],
f: ["Huggin'"],
g: ['Skillet'],
h: ['Flash'],
i: ['QT'],
j: ['Cheese'],
k: ['Pony'],
l: ['Bling'],
m: ['Stanky'],
n: ['Sparkle'],
o: ['Goof'],
p: ['High Five'],
q: ['Lover'],
r: ['Beef'],
s: ['Eazy'],
t: ['Baller'],
u: ['Backstage'],
v: ['Tuff'],
w: ['Chill'],
x: ['Zing'],
y: ['Fleek'],
z: ['DanceDance']
}
};
import React, { useState } from "react";
import { boybandData } from "./boy-band";
function BoyBandNameGenerator() {
const [generatedBoybandName, setGeneratedBoybandName] = useState("");
const [userInitial, setUserInitial] = useState("");
const [userZodiac, setUserZodiac] = useState("");
function handleChange(e) {
e.preventDefault();
const selectId = e.target.id;
if (selectId === "name-select") {
setUserInitial(e.target.value);
if (userZodiac) {
setGeneratedBoybandName(
`${boybandData.initial[e.target.value][0]} ${
boybandData.zodiac[userZodiac][0]
}`
);
}
} else if (selectId === "zodiac-select") {
setUserZodiac(e.target.value);
if (userInitial) {
setGeneratedBoybandName(
`${boybandData.initial[userInitial][0]} ${
boybandData.zodiac[e.target.value][0]
}`
);
}
}
}
return (
<form>
<label htmlFor="name-input">First Initial</label>
<select
id="name-select"
required
onChange={handleChange}
value={userInitial}
>
<option value="" disabled>
First Initial
</option>
{Object.keys(boybandData.initial).map((initial) => {
return (
<option key={initial} value={initial}>
{initial.toUpperCase()}
</option>
);
})}
</select>
<label htmlFor="zodiac-select">Zodiac Sign</label>
<select
id="zodiac-select"
required
onChange={handleChange}
value={userZodiac}
>
<option value="" disabled>
Zodiac Sign
</option>
{Object.keys(boybandData.zodiac).map((zodiac) => {
return (
<option key={zodiac} value={zodiac}>
{zodiac}
</option>
);
})}
</select>
<div>
<output htmlFor="initial-select zodiac-select" aria-live="polite">
{generatedBoybandName || ""}
</output>
</div>
</form>
);
}
export default BoyBandNameGenerator;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment