logo

Let's Practice Vocab 01-02

01-02 Let's Practice Vocab

TOPIC: Start ボタンの処理

CHECK

  1. questionAnswersContainerEl, headerContainerEl, headerSmallElを設定
  2. currentQuestionIndex変数の設定
  3. startGame()
    1. currentQuestionIndexを 0 に初期化する
    2. questionAnswersContainerEl についている hide を消し、表示する
    3. スタート画面の Header を消す
    4. 小さな Header を画面上部に表示する
  4. setNextQuestion()を作る
    1. console.log()が表示されるかを確認
  5. 質問画面に移るかを確認
// ELEMENTS
// --------------------------------

// 画面最初のスタートボタン
const startBtnEl = document.getElementById("start-btn")
// NEW!!
// QuestionボックスとAnswersボックスが入っているElement
const questionAnswersContainerEl = document.getElementById(
  "question-answers-container"
)
// NEW!!
// ゲーム開始時のHeaderを表すElement
const headerContainerEl = document.getElementById("header-container")
// NEW!!
// ゲームが始まったあとの画面上部の小さなHeaderを表すElement
const headerSmallEl = document.getElementById("header-small")

// VARIABLES
// --------------------------------

// ランダムにシャッフルされたQuestionオブジェクトが入っているarray
let shuffledQuestions

// NEW!!
// 現在の問題のIndex番号(1ずつたされる)
let currentQuestionIndex

// EVENT LISTENERS
// --------------------------------

// スタートボタンのクリックを聞くListener
startBtnEl.addEventListener("click", startGame)

// FUNCTIONS
// --------------------------------

// ゲームを始めるFunction
function startGame() {
  // スタートボタンを隠す
  startBtnEl.classList.add("hide")
  // questions array にある全てのQuestionオブジェクトをランダムに並べ替える
  shuffledQuestions = questions.sort(() => Math.random() - 0.5)

  // NEW!!
  // currentQuestionIndexを0に設定する
  currentQuestionIndex = 0
  // NEW!!
  // questionAnswersContainerEl についてhideを消し、表示する
  questionAnswersContainerEl.classList.remove("hide")
  // NEW!!
  // スタート画面のHeaderを消す
  headerContainerEl.style["display"] = "none"
  // NEW!!
  // 小さなHeaderを画面上部に表示する
  headerSmallEl.classList.remove("hide")

  // NEW!!
  // 次の質問を表示する
  setNextQuestion()
}

// NEW!!
// 次の質問を表示するFunction
function setNextQuestion() {
  console.log("NEXT QUESTION!!")
}

const questions = [
  {
    target_num: 1,
    jp: "現代の科学技術は私たちの生活を大いに[向上させた]。",
    en: "Modern technology has greatly (     ) our lives.",
    answers: [
      {
        text: "considered",
        correct: false,
      },
      {
        text: "improved",
        correct: true,
      },
      {
        text: "concerned",
        correct: false,
      },
      {
        text: "included",
        correct: false,
      },
    ],
  },
  {
    target_num: 2,
    jp: "生活の質はエネルギー使用に直接[関連し]てはいない。",
    en: "The quality of life is not directly (     ) to energy use.",
    answers: [
      {
        text: "produced",
        correct: false,
      },
      {
        text: "related",
        correct: true,
      },
      {
        text: "provided",
        correct: false,
      },
      {
        text: "improved",
        correct: false,
      },
    ],
  },
  {
    target_num: 3,
    jp: "言語はすべて私たちに社会に関する貴重な情報を[与える]ことができる。",
    en: "All languages can (     ) us with valuable information about society.",
    answers: [
      {
        text: "provide",
        correct: true,
      },
      {
        text: "include",
        correct: false,
      },
      {
        text: "relate",
        correct: false,
      },
      {
        text: "concern",
        correct: false,
      },
    ],
  },
]
Let's Practice Vocab 01-02 | LET'S PROG