gpt4 book ai didi

javascript - 我正在制作抽认卡游戏,但 "Next"按钮不起作用

转载 作者:行者123 更新时间:2023-11-27 22:53:20 25 4
gpt4 key购买 nike

我正在制作一个“下一步”按钮以移动到该游戏中的下一张抽认卡,但是当我点击该按钮时,没有任何反应。我不知道我做错了什么。

我在这段代码中使用了很多变量,例如用于说明问题和答案的数字变量。我尝试每次都向 number 变量添加一个,以将其更改为下一个问题,但它不起作用。

    <div id="flashcard" onclick="flip()"><h1 id="word"></h1></div>
<br>
<button onlick="next()">Next</button>
<script>
var questions;
questions = ['artistic','daring','good','sports-minded','messy','disorganized','studious','funny','impacient','intelligent','neat','patient','lazy','shy','serious','nice','sociable','talented','hardworking','boy','girl','male friend','female friend','I','he','she','very','according to my family'];
var answers = ['artístico, artística','atrevido','bueno, buena','deportista','desordenado, desordenada','estudioso, estudiosa','gracioso, graciosa','impaciente','intelligente','ordenado, ordenada','paciente','perezoso, perezosa','reservado, reservada','serio, seria','simpático, simpática','sociable','talentoso, talentosa','trabajador, trabajadora','el chico','la chica','el amigo','la amiga','yo','él','ella','muy','según mi familia'];
var number = 0;
var answer = answers[number];
var word = questions[number];
var display = document.getElementById('word');
display.innerHTML = word;
function flip(){
if(word == questions[0]){
display.innerHTML = answer;
}
if (word == questions[1]){
display.innerHTML = answer;
}
if (word == questions[2]){
display.innerHTML = answer;
}
if (word == questions[3]){
display.innerHTML = answer;
}
if (word == questions[4]){
display.innerHTML = answer;
}
if (word == questions[5]){
display.innerHTML = answer;
}
if (word == questions[6]){
display.innerHTML = answer;
}
if (word == questions[7]){
display.innerHTML = answer;
}
if (word == questions[8]){
display.innerHTML = answer;
}
if (word == questions[9]){
display.innerHTML = answer;
}
if (word == questions[10]){
display.innerHTML = answer;
}
if (word == questions[11]){
display.innerHTML = answer;
}
if (word == questions[12]){
display.innerHTML = answer;
}
if (word == questions[13]){
display.innerHTML = answer;
}
if (word == questions[14]){
display.innerHTML = answer;
}
if (word == questions[15]){
display.innerHTML = answer;
}
if (word == questions[16]){
display.innerHTML = answer;
}
if (word == questions[17]){
display.innerHTML = answer;
}
if (word == questions[18]){
display.innerHTML = answer;
}
if (word == questions[19]){
display.innerHTML = answer;
}
if (word == questions[20]){
display.innerHTML = answer;
}
if (word == questions[21]){
display.innerHTML = answer;
}
if (word == questions[22]){
display.innerHTML = answer;
}
if (word == questions[23]){
display.innerHTML = answer;
}
if (word == questions[24]){
display.innerHTML = answer;
}
if (word == questions[25]){
display.innerHTML = answer;
}
if (word == questions[26]){
display.innerHTML = answer;
}
}
function next(){
number = number + 1;
display.innerHTML = word;
} //this is the function I need help on.
</script>
<style>
@import url('https://fonts.googleapis.com/css?family=Patrick+Hand+SC&display=swap');
#flashcard{
width:400;
height:250;
background:#fff555;
position:relative;
}
#word{
position:absolute;
transform:translate(-50%,-50%);
top:110px;
left:50%;
font-family: 'Patrick Hand SC', cursive;
}
</style>

我想要发生的是当用户点击“下一步”按钮时,它会切换到下一张闪存卡。

最佳答案

函数可能如下所示。顺便说一句,你在 onlick="next()"

中有错别字

var questions;
questions = ['artistic', 'daring', 'good', 'sports-minded', 'messy', 'disorganized', 'studious', 'funny', 'impacient', 'intelligent', 'neat', 'patient', 'lazy', 'shy', 'serious', 'nice', 'sociable', 'talented', 'hardworking', 'boy', 'girl', 'male friend', 'female friend', 'I', 'he', 'she', 'very', 'according to my family'];
var answers = ['artístico, artística', 'atrevido', 'bueno, buena', 'deportista', 'desordenado, desordenada', 'estudioso, estudiosa', 'gracioso, graciosa', 'impaciente', 'intelligente', 'ordenado, ordenada', 'paciente', 'perezoso, perezosa', 'reservado, reservada', 'serio, seria', 'simpático, simpática', 'sociable', 'talentoso, talentosa', 'trabajador, trabajadora', 'el chico', 'la chica', 'el amigo', 'la amiga', 'yo', 'él', 'ella', 'muy', 'según mi familia'];
var number = 0;
var answer = answers[number];
var word = questions[number];
var display = document.getElementById('word');
display.innerHTML = word;
function flip() {
if (word == questions[0]) {
display.innerHTML = answer;
}
if (word == questions[1]) {
display.innerHTML = answer;
}
if (word == questions[2]) {
display.innerHTML = answer;
}
if (word == questions[3]) {
display.innerHTML = answer;
}
if (word == questions[4]) {
display.innerHTML = answer;
}
if (word == questions[5]) {
display.innerHTML = answer;
}
if (word == questions[6]) {
display.innerHTML = answer;
}
if (word == questions[7]) {
display.innerHTML = answer;
}
if (word == questions[8]) {
display.innerHTML = answer;
}
if (word == questions[9]) {
display.innerHTML = answer;
}
if (word == questions[10]) {
display.innerHTML = answer;
}
if (word == questions[11]) {
display.innerHTML = answer;
}
if (word == questions[12]) {
display.innerHTML = answer;
}
if (word == questions[13]) {
display.innerHTML = answer;
}
if (word == questions[14]) {
display.innerHTML = answer;
}
if (word == questions[15]) {
display.innerHTML = answer;
}
if (word == questions[16]) {
display.innerHTML = answer;
}
if (word == questions[17]) {
display.innerHTML = answer;
}
if (word == questions[18]) {
display.innerHTML = answer;
}
if (word == questions[19]) {
display.innerHTML = answer;
}
if (word == questions[20]) {
display.innerHTML = answer;
}
if (word == questions[21]) {
display.innerHTML = answer;
}
if (word == questions[22]) {
display.innerHTML = answer;
}
if (word == questions[23]) {
display.innerHTML = answer;
}
if (word == questions[24]) {
display.innerHTML = answer;
}
if (word == questions[25]) {
display.innerHTML = answer;
}
if (word == questions[26]) {
display.innerHTML = answer;
}
}

function next() {
number++;
answer = answers[number];
word = questions[number];
display.innerHTML = word;
} //this is the function I need help on.
@import url('https://fonts.googleapis.com/css?family=Patrick+Hand+SC&display=swap');
#flashcard{
width:400;
height:250;
background:#fff555;
position:relative;
}
#word{
position:absolute;
transform:translate(-50%,-50%);
top:110px;
left:50%;
font-family: 'Patrick Hand SC', cursive;
}
<div id="flashcard" onclick="flip()"><h1 id="word"></h1></div>
<br>
<button onclick="next()">Next</button>

关于javascript - 我正在制作抽认卡游戏,但 "Next"按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57813721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com