Why isn't my code printing to the console?

const userName = "Melissa";

userName === "Melissa" ? console.log(`Hello ${userName}`)
      : console.log("Hello!");

const userQuestion = "Will I take a lot of computer science classes?";

console.log(`The user asked: ${userQuestion}`);

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

switch(randomNumber){
    
  case "0": 
    console.log("It is certain")
    break;
        
     case "1": 
    console.log("It is decidedly so")
    break;
    
     case "2": 
    console.log("Reply hazy try again")
    break;
    
     case "3": 
    console.log("Cannot predict now")
    break;
    
     case "4": 
    console.log("Do not count on it")
    break;
    
     case "5": 
    console.log("My sources say no")
    break;

     case "6": 
    console.log("Outlook not so good")
    break;
    
     case "7": 
    console.log("Signs point to yes")
    break;
}

Printing:

Hello Melissa
The user asked: Will I take a lot of computer science classes?

As you can see, my console.logs are not printing to the screen.

that very likely means none of the cases are true, we could confirm this by adding a default to see if that is printed

if that is the case (pun intended), something is wrong with the comparisons

Nevermind I figured it out… the value output for my variable is a number, but I had it set to strings… So it wasn’t the same.

1 Like

i know, and i could have told you the answer, but getting there yourself teaches you so much more :slight_smile: Know you had some crucial thinking steps like: Why are my conditions not correct?

Thanks!

It is better when I figure it out myself :slight_smile: I was super happy!

2 Likes