Struggling With Mystery Word Game

The instructors weren’t kidding when they said that this is a big weekly project (The Mystery Word Game) that we have to be very careful with our programming. The purpose this weekly project was to implement the game Mystery Word as a web application where the user will be playing against the computer. For this project, I have already NPM install express, mustache-express, express-session, and body-parser to be used throughout the programming.

The idea of the Mystery Word Game:

  • A new user arrives (who hasn’t signed up) arrives at the root page, the app will select a random word from the list of words that YOUR computer has in store.
    • How are we supposed to access this list of words? We must be able to receive it with Node.
  • Store the chosen word during a session
    • We must use express-session
  • Note that the word chosen will not be shown. The user must guess a letter for that word. Basically, it is like a hangman game (which it really is anyway).
    • A form must be used where it can validate only one letter is being sent.
    • If more than one letter is entered–it must show that the input is invalid and tell the user to try again
  • Whatever letter is guessed that is not the correct letter for a chosen word–it must be shown somewhere on the page so that the user knows what letter they already used.
    • This is where express-session come in play
  • Whatever letter that is guessed and is correct will be shown on the display of a chosen word–but it will be partially shown until all the necessary words are added
    • Will need to somehow show those “underscores” where the missing letters are shown.
  • A user is allowed eight guesses where they will be reminded how many guesses they have left after each round of letter guessing.
    • Again, express-session plays a role here

This may sound easy to do–but I don’t think so, especially if this is not planned out accordingly before actually program the steps. Already, I find myself having issues with using the for loop inside the web app that is not displaying the words that I needed. I have already done the simple for loop outside of the web app to ensure that I am programming it correctly…and still, it is not working. Perhaps my brain is a bit tired that I am overlooking a very simple solution to this.

I am currently hard coding the first steps which are to use the for loop to go through an array and for some reason, it is not working when I am asking for the correct element and push it to a new array to single out the word.

Below is the code I’ve been working on and it is the first step to programming the game which for some reason is not displaying the word on the root page. Before I did the for loop, it does display the example words when I used the mustache tag (used the node library called express-mustache). Now, I brought in the for loop to get it to show up only one word instead of the whole array…it decides to not display any of the words. So, it is a struggle for me but I know it has to be a simple solution and/or I am practically overlooking something.

const example = ['cat', 'dog', 'horse', 'flea', 'mite', 'shark', 'fish', 'seahorse', 'graywolf'];

const game = [ ];

app.get('/', function(request, respond){

for (let i = 0; i > example.length; i++){
if (example[i] === "flea"){

respond.render('index', {
DropWord: game,}

Note: This is only partial programming I am showing as I have a lot more codes in the app.js file currently. I am doing the programming in baby steps to ensure that one block of code works before working on the next block of code.

Coding in Javascript Rants

This is going to be of a rant.

Learning a programming language is going to be hard. It is not that I can’t learn it. When I studied the materials on the fundamentals of Javascript such as functions, conditional flow, objects and arrays–I understood how it works. What threw me off is learning how to write it from scratch that points to logical steps by steps. Basically, I needed to learn how to think like a developer, telling the “dumb” computer what it is I wanted it to do by providing the rigid instructions.

That was the wall I hit.

And that is the wall I needed to knock it down.

And I will knock it down.

When I coded in javascript for the first time yesterday–I kept knocking down that wall little by little and my brain slowly made the connection, dot by dot, on learning how to think like a developer. That is pretty much how I felt–but I knew it would take time to truly understand the language to where I can manipulate the codes freely without being a bit scared of whether it works or not–or if I’m writing the code correctly.

HTML and CSS are my comfort zone and it is time for me to step out of it and move on with javascript. So, I better fail quick and learn quick (as my instructors told us).