这有点像命运之轮。我已经将一个随机数组条目拆分为单个字母,并且我正在尝试编写一个脚本,让我能够从数组中猜测一个字母。完整代码在下面。
var movietitles = ['Iron Man', ' Jaws', 'Avengers', 'Evil Dead', 'It', 'Transformers', 'Little Mermaid', 'Mulan', 'Scooby Doo', ];
const selection = movietitles[Math.floor(Math.random() * movietitles.length)];
let text = selection;
const game = text.split("");
for (var i = 0; i < game.length; i++) {
var newEl = document.createElement('p');
var newNode = document.createTextNode(game[i]);
newEl.appendChild(newNode);
document.body.appendChild(newEl);
var tile = document.getElementsByTagName('p');
}
function guessLetter() {
alert('Function called!');
userInput.value = '';
}
var userInput = document.getElementById('entry');
userInput.addEventListener('change', function() {
guessLetter(userInput.value);
});
p {
float: left;
margin: 10px;
background-color: white;
}
body {
background-color: lightgray;
margin-top: 100px;
}
.tile {
width: 50px;
height: 50px;
float: left;
background-color: black;
margin: 10px;
}
<div id=display></div>
<span>Please guess a letter or the whole title </span><input type=text id=entry>
我什么都没试过因为我完全被这个难住了
1条答案
按热度按时间oxiaedzo1#