Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function yayOrNay() {
  return new Promise((resolve, reject) => {
    const val = Math.round(Math.random() * 1) // 0 or 1, at random
    val ? resolve('Lucky!!') : reject('Nope 😠')
  })
}
async function msg() {
  // use try..catch to handle any potential errors
  // when using "async / await"
  try {
    const msg = await yayOrNay();
    console.log(msg)
  } catch(err) {
    console.log(err)
  }
}
msg()
msg()
msg()
msg()
msg()
msg()
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x