Memory Game with OOJS & Rails
Who else loves Wreck It Ralph?
I chose to create a memory game using the Wreck It Ralph characters for my Mod 4 project at Flatiron School. It uses mostly OOJS(Object Oriented JavaScript) for the frontend and Rails for the backend.
This is the frontend where you’ll find the memory game. The biggest learning curve was understanding and implementing the fetch requests. A fetch request is asynchronous and returns a Promise from an end point like this, “http://localhost:3000/api/v1/games" (an asynchronous method will run while other functions are executed). If it finds what we’re looking for then we would like a javascript object returned which is what happens in the first .then method. In the second .then method I’m asking it to retrieve the cards from the returned object (the game) and for each card we are creating a new Card instance.
Below is another example of a fetch request except this time it’s a POST request. The player’s input (their username and password) is made into JSON strings. The response is converted to a javascript object. I’m getting the username from the object and using it to render a greeting to the player.
Go play the game — enjoy! You can find the backend repo here. And the frontend repo here.