
All we need to do here is to access the data of the current step with bracket notation, check if it even exists, and then log the corresponding message.

As the name implies, we'll be using this function to log our messages to the browser's console.

Such a function can be accessed just like a usual object property and is generally referenced to as a method. It's available on the global object called document that's available everywhere in your code, in any web browser. To do this, we have to use a special addEventListener function, provided to us through one of the Web APIs. We want to listen only to two events - y and n key presses. We'll first set up our event listeners - functions that will be called when the specified event happens - e.g., mouse click or keypress. codepen.io and console window Event listeners Inside of it, we'll make all the needed preparations to set up our game. First, create a startGame function and call it immediately after. So, let's go to codepen.io - a simple, online code editor (but you can use anything else you want) - and open the browser's console (usually with F12 key), as these are the places that we're interested in.

Instead, we'll utilize the system of events and callbacks (functions that are executed in response to something happening). But, in our case, as our game is relatively simple and we don't have any complicated logic to implement, we don't have to use a game loop. To put it simply - it's a loop that runs the game logic. Most games come with what's called a game loop at their cores. In this way, we'll not only improve our current JavaScript knowledge but also learn a thing or two about events, Web APIs, and problem-solving thinking too! The core To answer them, he'll be using the y and n keys on the keyboard. For the sake of simplicity, let's say that the player will interact with the game through the browser's console and a system of yes or no questions. It'll be a Role-Playing Game (RPG), where the user becomes the main hero of our story. Let's get started!įirst, we need to decide on how our game should work. In this post, we'll utilize obtained knowledge to create a simple, console-based RPG game. In the two previous posts of this JS beginner-tailored series, we've covered some programming concepts and terms, together with the basics of JS. For anyone affected and seeking guidance for the related topic, contact me through Twitter DM, my Facebook Page, or email, and we should work something out!

This series has been discontinued without a proper ending.
