Skip to content

Instantly share code, notes, and snippets.

@audunolsen
Last active September 11, 2023 20:30
Show Gist options
  • Save audunolsen/aa3642f698e986ced42f09e1d53405dc to your computer and use it in GitHub Desktop.
Save audunolsen/aa3642f698e986ced42f09e1d53405dc to your computer and use it in GitHub Desktop.
/*
* Here's an alternative approach that uses the ternary operator instead of `if/else`.
* It does just the same as the other example just expressed slightly differently.
*
* DOCS: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator
*/
const secret = "coconut"
const guess = prompt()
const response = guess === secret ? "Ding ding!!" : "Nope…"
alert(response)
const secret = "coconut"
const guess = prompt()
if (guess === secret) {
alert("+10 points")
} else {
alert("No bueno")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment