Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

149
Views
How to make sweetAlert (swal) behave like the regular js alert function?

I am trying to make a "sweetalert2" box appear when the number of coins in a running game is 20. (I want to let the user know that they have reached 20 coins). If I just used alert, an alert box appears and the game pauses. However, I want to use the sweetalert box for better looks, but even when the box appears, the game still goes on running. How do I stop the game when the sweetalert box appears? The alert function handles this perfectly but it will be too plain for the game. Here is the sweetalert code that I have:

swal({
 allowOutsideClick: false,
  title: 'You have 20 coins',
  html:
    '<input id="swal-input1" class="swal2-input">' +
    '<input id="swal-input2" class="swal2-input">',
  preConfirm: function () {
    return new Promise(function (resolve) {
      resolve([
        $('#swal-input1').val(),
        $('#swal-input2').val()
      ])
    })
  },
  onOpen: function () {
    $('#swal-input1').focus()
  }
}).then(function (result) {
  swal(JSON.stringify(result))
}).catch(swal.noop)
7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.