Problems with Or operator

Dear Community,
Good mornings,
I have problems with the or operator, in this exercise i need to fix the script so it correctly tests the " money " and “today” variables so it prints out this message:
“It is Friday, but i don´t have enough money to go out”.
I tried many times even changing the or operator for the and operator but it seems it doesn´t work, i was also looking for an operator which can have the meaning of “but”
I will appreciate and thank you all for any help or advise in this code, thank you in advance!!!

var money = 9;
var today = 'Friday'

if ( money >= 100 || today === 'Friday' ) {
  alert("Time to go to the theater");    
} else if ( money >= 50 || today === 'Friday' ) {
  alert("Time for a movie and dinner");    
} else if ( money > 10 || today === 'Friday' ) {
  alert("Time for a movie");   
} else if ( money < 10 ||  today === 'Friday' ) {
  alert("It's Friday, but I don't have enough money to go out");   
} else {
  alert("This isn't Friday. I need to stay home.");
}

with the OR operator it is enough for one of the two conditions to be true for the if statement to execute
today === "Friday" is true so this statement will run

Can you show what you tried to do? How did you try to fix it?
You said you tried many things with the AND operator, but it doesn’t appear in the code you posted

also, what should happen when money === 10?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

Dear @ilenia,
Thank you so much for your fast reply and kindness, yes i tried to find a solution using the and operator, here are my alternatives of solutions:

var = 9;
var today = "Friday";

} else if ( money < 10  &&   today === 'Friday' ) {
  alert("It's Friday, but I don't have enough money to go out");   

or i also add here:

} else if (money !== 9 && today === "Friday"){
alert("It´s Friday, but i don´t have enough money to go out");

or perhaps can i also try this :

} else if (money <= 9 && today === "Friday"){
alert ("It´s Friday, but i don´t have enough money to go out");

It is possible to find an operator which means “but” ?

thank you so much for any advise i appreciate it dear @ilenia ,
Kind regards,
Ivonne

please format your code properly…

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

I am so sorry i will do it now, thank you @ilenia,
Kind regards,
Ivonne

if you changed just that, it will not work

as long as the OR operator is used for all statements, the first statement that has a today === "Friday" as a condition than it will execute

you can’t just change the line with the line you want,
you need to change all the conditions

should this:

should this execute only when there are more than 100 in money OR is friday, or only when both there are more than 100 money AND is friday?

1 Like

Dear @ilenia,

So i need to change all the conditions in order the code Works,
about the code you mention i guess it refers that both conditions are true when there are more than 100 money and is friday.

But the task is the following

Something’s wrong with this script. The value in the variable money is only 9.

But if you preview this script you’ll see the Time to go to the theater message.

Fix this script so that it correctly tests the variables money and today and prints out the proper alert message: “It’s Friday, but I don’t have enough money to go out”

Therefore i tried to change just the line where the alert message it´s Friday, but i don´t have enough money to go out

I guess i need to change all the conditions so the code runs

the if statement that execute is the first one for which the condition is true, so if now the first one is excuting it means that its condition is evaluating as true, if it shouldn’t execute then its condition should evaluate as false, ergo, you need to change the condition of the first if statement so that it evaluates as false instead of true

1 Like


FreeCodeCamp has a wonderful article on logical operators, give it a read and hopefully that will help you.

1 Like

I think that a lot of your difficulty is coming from translating natural language into code. There is no “but” operator, but you don’t need one. In each if statement, you are looking at a pair of conditions. You either need at least one of the statements to be true (logical OR) or you need both of the statements to be true (logical AND). (There is also the logical XOR, when you want exactly one of the statements to be true but not both.)

1 Like

Dear @ilenia,
Good morning,
I thank you and appreciate your kindness and help in this task,
i have changed all the conditions, so knowing that with the Or operator
if just one of the conditions is true the large condition evaluate to true,
i changed all the conditions to be false, but in the last one i left it to true.
Although i accomplish the challenge because in the preview screen it accomplish
the task.
Sadly it continues to show me an error, this is the message i get:
Hmm. Looks like there is at least one logical OR operator – that’s the || symbols.
Those test if just one of the conditions are true.

Dear @caleb-mabry,
Good morning,

Thank you so much for your kindness and help in this task,
i will read the information you sent me, thank you again,
Kind regards,
Ivonne

Where is this challenge?
You have a link?

1 Like

Dear @JeremyLT,
Good morning,
I appreciate and thank you for the explanation,
i guess it is true perhaps trying to translate everything literal
is now my problem, again i thank you so much for the input,
i will check it very good and restart the challenge,
Kind regards,
Ivonne

Dear @padunk,
Good morning,
Thank you so much for the reply, i send you here
in a picture the challenge,


thanks again :pray:
all the advises are welcome
Kind regards,
Ivonne

and do you still have a || OR operator in your code?

1 Like

Dear @ilenia,
Thank you for the fast reply, yes i put the or operator in my code,
so sorry to send you now a picture , here are the changes i made


thank you in advance for the consideration and your kindness i appreciate it, :pray:
Ivonne

I think the challenge trying to teach you about differences between && operator and || operator.
OR operator will execute if one of the conditions is true
AND operator will execute if both of the conditions are true.
Your conditions should test if both conditions are true.
So you need to use && operator.
And revised how you check the variable money on the last if else
You should be good to go.

2 Likes

all the conditions still have the OR operator… you will never pass that test, if your conditions all have the OR operator

you don’t have to change the conditions, you just have to make sure that both conditions have to be true for the code in that block to execute

first if statement should execute when you have 100 or more money AND is Friday
but if you have just 10$ on Tuesday it will say to go to the teather. You can’t, as you don’t have enough money and it is the wrong day

it seems you did the wrong changes

1 Like