I need run this code and solv all problems in it. tell me the problems , and how to solv it. project: How do I show the number of the letter's place in English, for example, if the user wrote a and pressed the button, the number 1 appears, and if wrote b, it appears 2 and so on. the code:
<!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>
You need to make the marked changes below for your code work. Read about Array.indexOf to understand how it works.
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>