dimanche 30 mai 2021

Swal.fire when click text in Javascript (Sweetalert)

I want to make appear a window promp with sweetalert (swal.fire) when i click a text. How do if statements and window prompt work on this library? After this point, you can appreciate that i'm new in this programming world.

After that, i would like to asign a value to that input and verify if the answer is correct or not.

<td class="gases" title="Hidrógeno" id="H">H</td> This is the element i want to click

Swal.fire({
title:'¿Cuál es el elemento?',
text: 'Introduce el nombre aquí',
input: 'text',
inputPlaceholder: 'Nombre', })

This is the prompt i want to appear when i cliked that element. When the button 'OK' is clicked, want to verify if the name introduced is correct or not...:

if (name === hidrógeno) {
     Swal.fire ('Correct!', 'You got the answer right!', 'success') }

else {
     Swal.fire ('Incorrect...', 'You failed!', 'error') }

Aucun commentaire:

Enregistrer un commentaire