If we take the Eight Ball project as a basis, am I actually improving or just going through the motions?

I have been going through the “Full-stack developer” career path, and It is hard for me to tell whether I am improving or not. I know that I just started, but sometimes it feels like I do the tasks like I am a programmable computer, and that is it. That I am not actually improving.
Recently I had to do the “JAVASCRIPT SYNTAX, PART I” Magic Eight Ball project.
I finished it by doing the bare minimum and ended with the following code:

let userName = 'Jane';
userName ? console.log(`Hello, ${userName}!`) : console.log('Hello!');

const userQuestion = 'Can I turn into a Werewolf?';
console.log(`You asked: ${userQuestion}`);

let randomNumber=Math.floor(Math.random() * 8);

let eightBall='';

switch (randomNumber) {
  case 0:
  eightBall='It is certain';
  break;
  case 1:
  eightBall='It is decidely so';
  break;
  case 2:
  eightBall='Reply hazy try again';
  break;
  case 3:
  eightBall='Cannot predict now';
  break;
  case 4:
  eightBall='Do not count on it';
  break;
  case 5:
  eightBall='My sources say no';
  break;
  case 6:
  eightBall='Outlook not so good';
  break;
  case 7:
  eightBall='Signs point to yes';
  break;
}

console.log(`The eight ball answered: ${eightBall}`); 

Afterward, I thought… Ok, If I AM IMPROVING, then I should be able to IMPROVE upon the CODE. Like, make it better in some fashion.
Of course, I understand that I have limited knowledge - just what I have been learning from the career path - not enough to make something groundbreaking, but still.
So, I looked at the code that I ended up with and tried to make it do the same, but in a more sophisticated matter and ended up with this:

const userName = ``; // ENTER YOUR NAME
    userName ? 
        console.log(`Hello, ${userName}!`) : 
        console.log('Hello!'); // Displays your name

const userQuestion = ``; // ENTER YOUR QUESTION
    if (!userQuestion) {
      console.log('I, the MAGICAL 8-BALL, have chosen you!')
    } else if (!userName) {
      console.log(`Stranger asked: ${userQuestion}`)
    } else if (userName) {
      console.log(`${userName} asked: ${userQuestion}`)
    } // Displays your question


let randomizer = ''; // The secret sauce that the magical 8-ball uses to determine the answer.
    if (userQuestion) {
        randomizer = Math.floor(Math.random() * 8)}; // If you asked a question, the 8-ball "randomly" determines the answer.
        const randomNumber = randomizer; // The answer is saved here.
            if (userQuestion) {
                console.log(`I BELIEVE THAT...`);
            } else if (!userQuestion) {
                console.log('');
            }; // Displays the beginning of the answer.

        switch (randomNumber) {
          case 0:
            console.log('It is certain');
            break;
          case 1:
            console.log('It is decidedly so');
            break;
          case 2:
            console.log('You should try asking me latter');
            break;
            case 3:
            console.log('This question is borring. Ask me a better one!');
            break;
          case 4:
            console.log('It is unlikely');
            break;
          case 5:
            console.log('My sixt-sense points to no');
            break;
            case 6:
            console.log('The outlook is not so good');
            break;
          case 7:
            console.log('The signs point to yes');
            break;
          default:
            console.log("Ask your question, mortal, and I shall grant you the absolute truth!");
            break;
        }; // Displays the actual answer to your question.

My question is: If you compare the two code snippets, does it look like I understand the subject matter well enough and I am improving, or is the answer some third option?

1 Like

In my opinion, you are improving. The second looks a lot more complex and it seems as if you know most of the basics.

1 Like

Thanks, it is nice to hear someone else’s perspective from time to time. :slight_smile:

1 Like