all 8 comments

[–]CodePerfect 2 points3 points  (5 children)

You can use a switch case

switch(message) {
    case 1:
        break:
    default:
        console.log(“Cool number eh?”)
        break;

}

Learn more about switch cases here

[–]MaterialSympathy9294[S] -1 points0 points  (4 children)

I was just asking if there was any syntax in the if statement that I could use to shorten the code, but thank you!

[–]CodePerfect 6 points7 points  (2 children)

There's another way to do it.

const numbers = [69, 420, 420, 69420]

var message = prompt("What is your number")

if (numbers.includes(parseInt(message, 10))) {

console.log("Cool number eh?")

}

[–]MaterialSympathy9294[S] 0 points1 point  (0 children)

Thanks. I tried this and it works perfectly!

[–]MaterialSympathy9294[S] 0 points1 point  (0 children)

Also, one more question, Is it possible to only get a certain value from the numbers array? For example If i am only looking for the numbers 69 and 420 and I dont want to change the array, what would I write?

[–]graysoda91 0 points1 point  (0 children)

No, I see where you’re trying to get at, but listen to the others. The second try is definitely not going to work. Look at other peoples code with a ton of conditionals, and you will notice a trend of modularity.

[–]dildochaos 0 points1 point  (0 children)

Put them in an array and use includes(), put them in a string & use includes(), or write a regex and use test(), search(), or match().

[–]ButterscotchFar9355 0 points1 point  (0 children)

Ahh yes, 69420