This take-home will give you practice with React through a fun and simple project. Additionally, the types of challenges you will be encountering here are actually very similar to React coding assessments that you might get when applying to front-end roles.
- Open your command line (Terminal) and cd (change directory) into the folder you would like to put this project in.
- Run
git clone https://github.com/VH-Mentorship/W2-TH-Magic-State-Ball.git
to copy this starter code. - Run
cd W2-TH-Magic-State-Ball
to access the directory. - Run
npm install
to install all the dependencies - Run
npm start
and check out this boring State Ball. - Open the folder in VSCode
- Take a look at the App.js file in the src folder. There is an array containing all the messages in line 8, and the first item (the 0 index) is displayed in line 15.
- We want to change the message when you click on the ball. This involves grabbing the event
onClick
from the<button>
. Similar to what we did in our todolist application, create a functionchangeMessage
that is called when you click on the<button>
by incrementing ourdisplayIndex
in the functionsetDisplayIndex
. - While this works, it doesn't provide the randomness or a real State Ball. Look up the random() function in Javascript, and use it to set our index to a random index within the array (that isn't 0).
- That's all! Click on your Magic State Ball, and use it to predict whether you'll pass your ISD test, or win a tumbler by going submitting feedback to https://vhl.ink/feedback.
*The solution code can be found in the completed
branch.
Following instructions is good and all, but very unlike what you'll be doing as a real developer. Complete these challenges, make this 8-ball your own, and show it off to friends and in the mentee-works
Discord channel! (TIP: Make Google searching your best friend)
- Modularize your code: That answerArray is over 100 characters, Yuck 🤢. Let's hide it in another file. Figure out how to put answerArray in its own file, export it, and import it into
App.js
! - More with states: Having a bad day? Create a checkbox that, when checked, will only let the 8-ball return positive phrases (i.e. "It is certain", "without a doubt"). You will need to create a new function to handle this, and make good friends with Stack Overflow and the documentation.
- What next? Make the ball shake when you click it with CSS animations, add functionality for a space bar, create a "leaderboard" of results based on how often they show up...Anything you want! Reach out to your pod leaders or in
mentee-works
for advice!