Necesito ejecutar este código y resolver todos los problemas que contiene. Cuéntame los problemas y cómo solucionarlos. proyecto: ¿Cómo muestro el número del lugar de la letra en inglés, por ejemplo, si el usuario escribió a y presionó el botón, aparece el número 1, y si escribió b, aparece 2 y así sucesivamente. el código:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Alpha Position Finder</title> <script> let alphabets=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] document.addEventListener('DOMContentLoaded',function() { document.querySelector("button").onclick = finder; function finder() {; var check = document.getElementById('text').innerHTML; } } </script> </head> <body> <div> <h1>Welcome to alpha position finder.</h1> <p id="position"></p> <input type="text" placeholder="Enter alphabet" id="text"> <button>Find</button> </div> </body> </html>Debe realizar los cambios marcados a continuación para que su código funcione. Lea acerca de Array.indexOf para comprender cómo funciona.
let alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; document.addEventListener('DOMContentLoaded', function() { document.querySelector("button").onclick = finder; function finder() { var check = document.getElementById('text').value; // <-- CHANGE console.log("indexOf( " + check + ") = " + alphabets.indexOf(check) ); // <-- ADD } }); <div> <h1>Welcome to alpha position finder.</h1> <p id="position"></p> <input type="text" placeholder="Enter alphabet" id="text"> <button>Find</button> </div>