#need help with javacsript

37 messages · Page 1 of 1 (latest)

long onyx
#

I dont know but my progran skips if statement and jumps onto the else if statement in javascript

#

@dusky swift

dusky swift
#

Brawnm

silent mesa
#

Try a console.log(day) in line 14 and see what comes to the day

uncut locust
#

don't use var for defining variables

#

this is so outdated way of defining them

dusky swift
#

Use let or constwolfshrug

long onyx
uncut locust
#

idk, it could be because of the order or those checks

#

for example I can't really understand why you have to check if it's saturday or sunday, as this sets the price 10 like that else block.

long onyx
#

Its like an app

#

You can choose say and your age

uncut locust
#

okay, but why do you need to check if the day is sunday or saturday and then set the price 10, when you could get the same price in else block?

#

You could getrid of that first if then?

long onyx
#

The thing is its the museum ticket generator

#

If you go on weekends the ticket price is 10

#

If you go on working days the tickets is 5

uncut locust
#

its not

#

5

#

you have set the price 10 in that else block

long onyx
#

But if you go on friday and have a discount code then price is 0

#

Its 10

#

@uncut locust

wheat reefBOT
#

@long onyx

File Attachments Not Allowed

For safety reasons we do not allow file and video attachments.

Code Formatting

You can share your code using triple backticks like this:
```
YOUR CODE
```

Large Portions of Code

For longer scripts use Hastebin or GitHub Gists and share the link here

Ignored these files
  • 20230113_092229.mp4
long onyx
#

Here is like the video of how the porgram runs

#

<@&934250633580658788>

#

Please helpp

brisk pike
#

Did you do the console log?

#

Cus if you log the input of what day it is you can see whats wrong

#

Using var here is weird ye, but also... Maybe check if your dropdown is actually not equal by the case sensitivity of your program? I aint exactly sure what else could cause it

green forge
#

Log all your variables and your outputs and just see what isn't what it's supposed to be
e,g add

//before the if statement
console.log(day);
console.log(age);
console.log(discount);


//after thje if statement
console.log(price);

Make sure everything is exactly as you expect it to be, it doesn't just skip if statements by accident so if it's not triggering it means one of them must be wrong

long onyx
#

@green forge

#

So my problem is my if statement does not run even though I have all the conditions true in if statement but it jumps into if else statement

green forge
#

Then your variables probably aren't returning what you expect, log them and check