Giter Site home page Giter Site logo

24.may.21_quizapp_vanilla-js's Introduction

πŸ’‘ Quiz App (μΌλ°˜μƒμ‹)

Demo

quiz

πŸ’» 1.ν”„λ‘œμ νŠΈ μ†Œκ°œ

πŸ“ μ‚¬μš©κΈ°μˆ  및 μ–Έμ–΄

  • Vanilla JS
  • CSS
  • HTML

⏰ 개발 κΈ°κ°„

2021-05-17 ~ 24

πŸ—’ 2.ν”„λ‘œμ νŠΈ λ‚΄μš©

μ£Όμš” κΈ°λŠ₯

  • 객관식 5문제 λ₯Ό ν•˜λ‚˜μ”© ν’€μ–΄μ„œ μ΅œμ’…μœΌλ‘œ λͺ‡κ°œ λ§Ÿμ£Όμ—ˆλŠ”μ§€ μŠ€μ½”μ–΄ κ³„μ‚°ν•˜μ—¬ 좜λ ₯

  • λ‹€μ‹œ ν•œλ²ˆ 더 (처음으둜 λŒμ•„κ°€μ„œ) λ²„νŠΌ 클릭 μ‹œ, 처음 문제둜 return

πŸ“Œ 3.μ£Όμš” μ½”λ“œ

function loadQuiz() {

  deselectAnswers();

  const currentQuizData = quizData[currentQuiz]; // set currentQuizData

  // put into HTML from quizData
  questionEl.innerText = currentQuizData.question;
  a_text.innerText = currentQuizData.a;
  b_text.innerText = currentQuizData.b;
  c_text.innerText = currentQuizData.c;
  d_text.innerText = currentQuizData.d;
}

// execute loadQuiz
loadQuiz();

function getSelected() {

  let answer = undefined;

  answersEls.forEach((answerEl) => {
    if (answerEl.checked) {
      answer = answerEl.id;
    }
  });

  return answer;

}

function deselectAnswers() {
  answersEls.forEach((answerEl) => {
    answerEl.checked = false;
  })
}


// add click btn to change next question
submitBtn.addEventListener('click', () => {
  // check to see the answer
  const answer = getSelected();

  if (answer) {
    if (answer === quizData[currentQuiz].correct) {
      score++;
    }
    // after clicking, next index in quizData
    currentQuiz++;
    if (currentQuiz < quizData.length) loadQuiz();
    else {
      quiz.innerHTML = `
      <h2>λ‹Ήμ‹ μ˜ μ μˆ˜λŠ”.. ${score}/${quizData.length} μž…λ‹ˆλ‹€.</h2>
      <button onclick = "location.reload()">λ‹€μ‹œ ν•œλ²ˆλ”!!</button>
      `
    }
  }
})

4. λŠλ‚€μ 

  • ν€΄μ¦ˆ 데이터λ₯Ό μ—¬λŸ¬ ν•¨μˆ˜λ₯Ό 톡해 (loadQuiz(), getSelected(), deselectAnswers()) 문제, μ •λ‹΅ 의 JS quizdata λ₯Ό λΉ„κ΅ν•˜κ³  DOM 을 μ‚¬μš©ν•΄μ„œ HTML λ¬Έμ„œμ— 좜λ ₯ ν•˜λŠ”λ²•μ„ λ°°μ› λŠ”λ°, ν•¨μˆ˜κ°€ μ—¬λŸ¬κ°€μ§€κ°€ μž‘λ™μ΄λ˜μ„œ μ½”λ“œλ₯Ό μ΄ν•΄ν•˜λŠ”λ° 어렀움이 μžˆμ—ˆλ‹€.

  • ν•˜λ‹¨λΆ€μ— λ²„νŠΌμ„ λ§Œλ“€μ–΄, click μ‹œ λ‹€μŒνŽ˜μ΄μ§€ μ „ν™˜ 및 score ++ ν•œλ‹€μŒ, μ΅œμ’… νŽ˜μ΄μ§€μ—μ„œ 점수λ₯Ό λ‚˜νƒ€λ‚΄μ£Όμ—ˆλ‹€. => 더 λ‚˜μ•„κ°€μ„œλŠ” μ™œ ? ν‹€λ ΈλŠ”μ§€ λ¬Έμ œμ—λŒ€ν•œ μ„€λͺ…κ³Ό λͺ‡λ²ˆ λ¬Έμ œκ°€ ν‹€λ ΈλŠ”μ§€ μ•Œλ €μ£ΌλŠ” κΈ°λŠ₯을 ν•™μŠ΅ 후에 μΆ”κ°€ ν•  μ˜ˆμ •μ΄λ‹€.

Reference

24.may.21_quizapp_vanilla-js's People

Contributors

jacobkosmart avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.