Monday 4 June 2018

JavaScript and database with QuizQuestions

In this post I would like to explain how to prepare container for questions in javaScript.
The main purpose of creating container similar to the database is to store the data, and display the data to the user - in this particular example it means that we need a container to store the questions of the quiz application.

The container is declared as constant and it contains desired data. Thanks by the vast posibilities of javaScript, we can specify which answer is correct, then use a script to compare correctAnswer with userInput.
Note that questions are strings data type and they have to be included between double-quote symbols, to show to the javaScript interpreter the type of the data.
const myQuestions = [
  {
    question: "Who is the strongest?",
    answers: {
      a: "Superman",
      b: "The Terminator",
      c: "Waluigi, obviously"
    },
    correctAnswer: "c"
  },
  {
    question: "What is the best site ever created?",
    answers: {
      a: "SitePoint",
      b: "Simple Steps Code",
      c: "Trick question; they're both the best"
    },
    correctAnswer: "c"
  },
  {
    question: "Where is Waldo really?",
    answers: {
      a: "Antarctica",
      b: "Exploring the Pacific Ocean",
      c: "Sitting in a tree",
      d: "Minding his own business, so stop asking"
    },
    correctAnswer: "d"
  }
];
Web design Hull Web design services Freelance web designer web design blog IT specialist Why is the mobile version of the website important? What it's SSL certificate and how it benefits website? The most important features for e-commerce store? Why website does not appear in Google results? Content marketing is a wide field in which our imagination is the only limitation What is the guideline when choosing a hosting for the website? What is worth paying attention to when designing your company's website? The value of blogging in the terms of website design. Freelance web designer - Why do you need affordable website? The ultimate guide how to become freelancer in 2020 6 Features of best UX for web design in 2020 How works Google Assistant. OK Google get started 6 website types which hit the trends in 2020. 10 reasons why CMS need to die in 2020. What is ZCash and how does this modern cryptocurrency work? 5 Best ways to make money online in 2020. How you can make money online - find something adequate to skills The comprehensive guide how to become programer in London - 2020.

1 comment:

  1. It's good to see posts being added to your blog now, but with such a gap it doesn't show great consistent use over the last couple of weeks. However you are showing a good level of progress and technical vocabulary.

    ReplyDelete