If Else Statement Issues

Hello! First of all, I want to thank you for taking time to help me.
I am very new to “coding” (started 2 weeks ago), and I am currently starting to learn javascript.
I’m having trouble with this if else statement.
I made up some BS types to make the ticket # look flashy but whenever i run the script it only runs the NRG differentTypes and idk why. it should be using the random number to choose one of the 4 options. Any help is appreciated.
P.S. I know my layout is super ugly please be nice. I’m still so new lol.

------------Fortune Teller-------
//Set Variables
//Type name between ‘’
let name = ‘’;
const question = ‘’;

/*+RGO=Very good odds
RGO=good odds
NRG=Not good odds
!NRG=Very bad odds
let randomNumber1 = Math.ceil(Math.random() * 4);
let differentTypes = randomNumber1;

if (randomNumber1 = 0){
else if (randomNumber1 = 1){
else if (randomNumber1 = 2){
else if (randomNumber1 = 3){

//creating a random number and assigning it to variable “randomeNumber”.
let randomNumber = Math.floor(Math.random() * 1000000);
//creating new variable for randomeNumber called fortune.
let ticketNumber = randomNumber;

/*–Using a ternary expression to decide what to do if the user has a name or not.–
name ? console.log(Hello ${name}, Welcome to Miss.Vickey's Fortune!) :
console.log(Hello! Welcome to Miss.Vickey's Fortune!);
*///rewriting with if else statement
if (name){
console.log(Hello ${name}, Welcome to Miss.Vickey's Fortune!);
else {
console.log(Hello! Welcome to Miss.Vickey's Fortune!);
console.log(Reference #: ${differentTypes}${ticketNumber});


Hi there,

Are you looking for the console to log something like this:

Hello KirativeWD, welcome to Miss.Vickey’s Fortune! You would like to know “can I learn JavaScript?”
The fortune says: Really good odds

If so, your code is close–but there are some issues. I’ve learned a lot from looking at the errors thrown by the console, and it should direct you as to what is wrong. I’d be more than happy to help you work them out if you still need assistance. :slight_smile:

1 Like

thank you for the reply, I changed the script to a zodiac animal info thing. I really appreciate you taking the time to help me, also I needed to === 0-3 for the if else statement. i don’t understand why though and I would like to. I have to go back and look at that section in the course.

When you write randomNumber1 = 0 you’re actually assigning the value 0 to the randomNumber1 variable instead of comparing its value to 0, because the equals sign (=) is the assignment operator.

When you wish to compare two values for equality you must use comparison operators: two equal signs (==) or three equals signs (===).

In a simplistic way, the difference between them is that the “==” operator allows comparisons between different types of data to hold true (like false == 0 or " " == false) through type coercion and the “===” operator doesn’t.


okay yeah that makes sense. thank you so much for your help! have a nice day :slight_smile: .

1 Like