第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

我正在制作抽認(rèn)卡游戲,但“下一步”按鈕不起作用

我正在制作抽認(rèn)卡游戲,但“下一步”按鈕不起作用

我正在制作“下一步”按鈕以移至此游戲中的下一張抽認(rèn)卡,但是當(dāng)我單擊該按鈕時(shí),什么也沒有發(fā)生。我不知道我做錯(cuò)了什么。我在這段代碼中使用了很多變量,例如數(shù)字變量來說明它是哪個(gè)問題和答案。我嘗試每次向 number 變量添加一個(gè),以將其更改為下一個(gè)問題,但它不起作用。    <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;}我想要發(fā)生的是當(dāng)用戶單擊“下一步”按鈕時(shí),它會(huì)更改為下一個(gè)閃存卡。
查看完整描述

2 回答

?
茅侃侃

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超21個(gè)贊

如果使用變量來訪問數(shù)組中的數(shù)據(jù),則可以大大簡化代碼 - 您不必對代碼中的每個(gè)索引進(jìn)行硬編碼。我想你希望你的代碼像這樣工作:


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'];


//Your code doesnt have to check every single index, just use a variable

var display = document.getElementById('word');

var next = document.getElementById('next');

let i = 0;


function flip(idx) {

  display.innerHTML = answers[idx];


  if (i < answers.length - 1) {

    //Increment the counter by 1 on each flip

    i += 1;

  } else {

    //Back to first card

    i = 0;

  }


}


//Flip the first card right away

flip(0);


//Add an event handler to the button to call flip when the button is clicked

next.addEventListener('click', () => {

  flip(i);

});

<input type="button" id="next" value="Next">

<div id="word"></div>


查看完整回答
反對 回復(fù) 2021-10-07
  • 2 回答
  • 0 關(guān)注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號