Next Life Predictions

Role

Codecademy portfolio project, 2021

JavaScript

Brief

This is a JavaScript project I did while taking the Codecademy Full-stack Engineer Career Path course. The task was to code a simple program that would return a combination of mixed messages every time a user runs it. I have chosen the theme of future life to create a predictions generator.

Logic of the code

Steps

There were a few options to complete the task, each of which would structure the JavaScript program in a different way. I chose to use objects, arrays, getters and a simple method, which would generate the final message for the user. By doing this the program would run the same way both in command line and on button click when used with HTML. The steps I took are as follows:

  • Use a function to generate a random number. It should take the length of an array as argument and use it as a maximum value later in the program.
  • Create an object to store 3 types of messages.
  • Create getter for each type of messages to return a random message.
  • Create object method to combine the randomly selected messages into a single one and print it when the method is called.

Try the code

See the Pen Next Life Predictions - Mixed Messages by Atanas Dimitrov (@atanasdim) on CodePen.

Codepen window