Skip to content

Commit 4e90f5b

Browse files
authored
Merge pull request #5 from KaylaKremer/update-2024
Update 2024
2 parents 65e7153 + 297afef commit 4e90f5b

19 files changed

+748
-460
lines changed

README.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
11
# Coderbyte React Challenges
22

3-
- This repo contains my solutions for the [React Interview Kit](https://coderbyte.com/interview-kit/react) challenges.
3+
- This repo contains my solutions for the [React & React Native challenges](https://coderbyte.com/challenges).
44

55
- All solutions received a 10/10 score.
66

77
- Feel free to use any of my solutions for yourself!
88

9-
### Update 1/8/23
9+
## Updates
1010

11-
I added the missing solutions to the newer challenges Coderbyte made for React/React Native since I first created this repo. As of now, all challenges are solved. Since this repo seems to be popular, I will try to periodically check and update it with more solutions if Coderbyte decides to add more React challenges.
11+
#### 1/8/23
1212

13-
### Update 6/13/23
13+
Added missing solutions for the newer challenges Coderbyte released.
1414

15-
Refactored a few solutions!
15+
#### 6/13/23
1616

17-
### Update 9/21/23
18-
Slight editing of README.
17+
Refactored a few solutions.
18+
19+
#### 9/21/23
20+
21+
Slight editing of `README`.
22+
23+
#### 1/20/24
24+
25+
- Refactored all previous solutions to use React 18 and use .jsx/.tsx file extensions
26+
- Redid solution for `tictactoe.jsx`
27+
- Added new solutions for the following challenges:
28+
- `color-dropdown.jsx`
29+
- `letter-tiles.jsx`
30+
- `live-paragraph.jsx`
31+
- `quiz-builder.jsx`
32+
- `weather-dashboard.jsx`
33+
- Updated `README``
34+
35+
## FAQ
36+
37+
**Can you include the challenge's question in your solution?**
38+
39+
Unfortunately, no since I don't want to violate Coderbyte's [Terms of Use](https://coderbyte.com/terms). My solutions are only meant as a resource to check against your own or just to study from in general! You'll need to pay for Coderbyte to see the questions to their code challenges.
40+
41+
**Do you accept submissions for alternative solutions?**
42+
43+
No, not at this time. I originally intended to use this repo as a way to keep a copy of my solutions I wrote when I ended my Coderbyte subscription. However, since this repo has grown in popularity, if there is more interest to open this repo up and accept alternative solution submissions, I may consider this!

solutions/button-toggle.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

solutions/button-toggle.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { useState } from "react"
2+
import { createRoot } from "react-dom/client"
3+
4+
const Toggle = () => {
5+
const [toggle, setToggle] = useState(false)
6+
7+
const handleClick = () => {
8+
setToggle(!toggle)
9+
}
10+
11+
return (
12+
<button type="button" onClick={handleClick}>
13+
{toggle ? "ON" : "OFF"}
14+
</button>
15+
)
16+
}
17+
18+
const root = createRoot(document.getElementById("root"))
19+
root.render(<Toggle />)

solutions/color-dropdown.jsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, { useState } from "react"
2+
import { createRoot } from "react-dom/client"
3+
4+
function ColorSelector() {
5+
const colors = { red: "Red", blue: "Blue", green: "Green" }
6+
const [color, setColor] = useState(colors.red)
7+
const onChange = e => setColor(e.target.value)
8+
return (
9+
<>
10+
<select onChange={onChange} value={color}>
11+
<option value={colors.red}>{colors.red}</option>
12+
<option value={colors.blue}>{colors.blue}</option>
13+
<option value={colors.green}>{colors.green}</option>
14+
</select>
15+
{color && <p>{`You have selected: ${color}`}</p>}
16+
</>
17+
)
18+
}
19+
20+
const root = createRoot(document.getElementById("root"))
21+
root.render(<ColorSelector />)
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, createContext, useContext } from "react"
2-
import ReactDOM from "react-dom"
2+
import { createRoot } from "react-dom/client"
33

44
const languages = ["JavaScript", "Python"]
55
const LanguageContext = createContext({
@@ -8,25 +8,14 @@ const LanguageContext = createContext({
88
setLanguage: () => {},
99
})
1010

11-
function App() {
12-
const [language, setLanguage] = useState(languages[0])
13-
return (
14-
<LanguageContext.Provider value={{ languages, language, setLanguage }}>
15-
<MainSection />
16-
</LanguageContext.Provider>
17-
)
18-
}
19-
20-
function MainSection() {
11+
const MainSection = () => {
2112
const { languages, language, setLanguage } = useContext(LanguageContext)
2213
const currentIndex = languages.indexOf(language)
23-
const toggleLanguage = () => {
24-
if (currentIndex === languages.length - 1) {
25-
setLanguage(languages[0])
26-
} else {
27-
setLanguage(languages[currentIndex + 1])
28-
}
29-
}
14+
const toggleLanguage = () =>
15+
currentIndex === languages.length - 1
16+
? setLanguage(languages[0])
17+
: setLanguage(languages[currentIndex + 1])
18+
3019
return (
3120
<div>
3221
<p id="favoriteLanguage">{`Favorite programming language: ${language}`}</p>
@@ -37,4 +26,14 @@ function MainSection() {
3726
)
3827
}
3928

40-
ReactDOM.render(<App />, document.getElementById("root"))
29+
const App = () => {
30+
const [language, setLanguage] = useState(languages[0])
31+
return (
32+
<LanguageContext.Provider value={{ languages, language, setLanguage }}>
33+
<MainSection />
34+
</LanguageContext.Provider>
35+
)
36+
}
37+
38+
const root = createRoot(document.getElementById("root"))
39+
root.render(<App />)

solutions/letter-tiles.jsx

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import React, { useState, useCallback, useMemo } from "react"
2+
import { createRoot } from "react-dom/client"
3+
4+
const style = {
5+
letterContainer: {
6+
overflow: "auto",
7+
marginBottom: "10px",
8+
display: "flex",
9+
flexWrap: "wrap",
10+
justifyContent: "center",
11+
alignItems: "center",
12+
},
13+
letter: {
14+
float: "left",
15+
padding: "10px 10px",
16+
background: "#c9e4ed",
17+
borderRadius: "5px",
18+
marginRight: "5px",
19+
marginTop: "5px",
20+
cursor: "pointer",
21+
},
22+
outputString: {
23+
marginTop: "20px",
24+
textAlign: "center",
25+
},
26+
}
27+
28+
const Tile = ({ letter, outputArray, setOutputArray, tally, setTally }) => {
29+
const onClick = useCallback(() => {
30+
if (!tally[letter]) {
31+
setTally({ ...tally, [`${letter}`]: 1 })
32+
setOutputArray([...outputArray, letter])
33+
} else if (tally[`${letter}`] && tally[`${letter}`] === 2) {
34+
setTally({ ...tally, [`${letter}`]: 0 })
35+
const slicedArray = outputArray.slice(0, outputArray.length - 2)
36+
setOutputArray([...slicedArray, "_"])
37+
} else {
38+
setTally({ ...tally, [`${letter}`]: tally[`${letter}`] + 1 })
39+
setOutputArray([...outputArray, letter])
40+
}
41+
}, [letter, outputArray, setOutputArray, tally, setTally])
42+
43+
return (
44+
<button type="button" onClick={onClick} style={style.letter}>
45+
{letter}
46+
</button>
47+
)
48+
}
49+
50+
const Application = () => {
51+
const [outputArray, setOutputArray] = useState([])
52+
const [tally, setTally] = useState({})
53+
const alphabetArray = useMemo(() => {
54+
let arr = []
55+
for (let i = 65; i <= 90; i++) {
56+
const char = String.fromCharCode(i)
57+
arr.push(char)
58+
}
59+
return arr
60+
}, [])
61+
return (
62+
<section>
63+
<aside style={style.letterContainer} id="letterContainer">
64+
{alphabetArray.map((letter, index) => (
65+
<Tile
66+
tally={tally}
67+
setTally={setTally}
68+
letter={letter}
69+
key={index}
70+
outputArray={outputArray}
71+
setOutputArray={setOutputArray}
72+
/>
73+
))}
74+
</aside>
75+
<div style={style.outputString} id="outputString">
76+
{outputArray.join("")}
77+
</div>
78+
</section>
79+
)
80+
}
81+
82+
const root = createRoot(document.getElementById("root"))
83+
root.render(<Application />)

solutions/list.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

solutions/list.jsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from "react"
2+
import { createRoot } from "react-dom/client"
3+
4+
const data = [
5+
{ name: "Daniel", age: 25 },
6+
{ name: "John", age: 24 },
7+
{ name: "Jen", age: 31 },
8+
]
9+
10+
const DataItem = ({ name, age }) => (
11+
<li>
12+
<span>{`${name} `}</span>
13+
<span>{age}</span>
14+
</li>
15+
)
16+
17+
const DataList = ({ data }) => (
18+
<div>
19+
<h2>Data List</h2>
20+
<ul>
21+
{data.map((dataItem, index) => (
22+
<DataItem
23+
name={dataItem.name}
24+
age={dataItem.age}
25+
key={`data-item-${index}`}
26+
/>
27+
))}
28+
</ul>
29+
</div>
30+
)
31+
32+
const root = createRoot(document.getElementById("root"))
33+
root.render(<DataList data={data} />)

solutions/live-paragraph.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React, { useState } from "react"
2+
import { createRoot } from "react-dom/client"
3+
4+
function LiveText() {
5+
const [text, setText] = useState("")
6+
7+
const onChange = ({ target: { value } }) => {
8+
setText(value)
9+
}
10+
return (
11+
<>
12+
<input type="text" onChange={onChange} value={text} />
13+
<p>{text}</p>
14+
</>
15+
)
16+
}
17+
18+
const root = createRoot(document.getElementById("root"))
19+
root.render(<LiveText />)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy