Create a simple quiz app using Json in Sketchware

To create a simple quiz app using Json String in Sketchware, follow the steps given below.

1. Create a json array containing all the questions and options. Each object in the array should contain a question with key 'ques', four options for the question with keys 'a', 'b', 'c' and 'd', and the correct answer with key 'ans'.

[
{
"ques" : "The larynx in adults lies in front of hypopharynx opposite the...",
"a" : "second to fifth cervical vertebrae",
"b" : "fifth to seventh cervical vertebrae",
"c" : "third to sixth cervical vertebrae",
"d" : "first two cervical vertebrae",
"ans" : "c"
},

{
"ques" : "Which of the following is the largest cartilage of larynx?",
"a" : "thyroid cartilage",
"b" : "cricoid cartilage",
"c" : "arytenoid cartilages",
"d" : "epiglottis",
"ans" : "a"
},

{
"ques" : "Which one of the following muscles is not a depressor of larynx?",
"a" : "sternohyoid",
"b" : "stylohyoid",
"c" : "sternothyroid",
"d" : "omohyoid",
"ans" : "b"
},

{
"ques" : "Barrets esophagus result in which type of carcinoma?",
"a" : "Adenocarcinoma",
"b" : "Squamous",
"c" : "Adenosquamous",
"d" : "Basal cell carcinoma",
"ans" : "a"
},

{
"ques" : "ADAM TS 13 is associated with",
"a" : "TTP",
"b" : "Churg Strauss",
"c" : "Wegener",
"d" : "Membranous nephropathy",
"ans" : "a"
},

{
"ques" : "T1/2 of Haptaglobin-Hb complex is",
"a" : "5 days",
"b" : "3 days",
"c" : "10 days",
"d" : "10 minutes",
"ans" : "d"
},

{
"ques" : "E-cadherin mutation is seen in which type of carcinoma?",
"a" : "IDC",
"b" : "Lobular carcinoma",
"c" : "Metaplastic carcinoma",
"d" : "Metastatic",
"ans" : "b"
},

{
"ques" : "Classical pathway Macrophage activating molecule?",
"a" : "IFN gamma",
"b" : "IL 13",
"c" : "IL 4",
"d" : "IL 1",
"ans" : "a"
},

{
"ques" : "Massive blood transfusion will cause all except?",
"a" : "Hypercalcemia",
"b" : "Hyperkalemia",
"c" : "Hypokalemia",
"d" : "Hypothermia",
"ans" : "a"
},

{
"ques" : "Durcks granuloma seen in?",
"a" : "Spleen",
"b" : "Heart",
"c" : "Brain",
"d" : "Lymphnode",
"ans" : "c"
}
]

A comma should separate all objects and all key-value pairs, from each other.

Learn about Json syntax here: http://www.sketchwarehelp.com/2018/06/json-syntax.html?m=1

2. In Sketchware project, on main.xml page add a Button button1, and a LinearH linear2. Inside linear2 add two TextViews textview1 and textview2.


3. In MainActivity.java add an Intent component i, and a file shared preferences component sp:sp.

4. Create a new page quiz.xml.

5. In MainActivity.java, add onStart event and in this event put blocks as in image below.
* These blocks will make linear2 visible when user returns to the page after completing the quiz, and display his score in textview2.

6. In button1: onClick event, use Intent to move to QuizActivity.

7. On quiz.xml page add four TextViews: textview1 for question number, textview2 for question, textview3 for the word 'Score:' and textview4 for the score. Also add four CheckBoxes for options checkbox1, checkbox2, checkbox3 and checkbox4, and a Button button1.

8. In QuizActivity.java add a file shared preferences component with name sp:sp, same as on MainActivity.java page.

Also add a List Map lmap, a Map variable vmap, three Number variables n, q and score, and a String variable answer.


9. Add three More Blocks, pickQuestion, falseCheckboxes, and
selected CheckBox... to answer String...

10. Define pickQuestion using blocks as shown below.
* It will increase the question number by 1.
* It will pick a random question from the Map List and get it to Map Variable.
* It will display the selected question and it's options in TextViews and CheckBoxes using their keys (The keys used here are same as those used in the Json String created in step 1).
* It will delete the selected question from the List Map.

11. In the QuizActivity, in onCreate event, put following blocks.


* Here n is for question number, and score is for score. Both are set to 0.
* The Json.... to ListMap lmap Block will convert the Json String (shown in step 1), into ListMap lmap.
* The pickQuestion block selects one question from the Map List.

12. Define falseCheckboxes using blocks as shown in image below.
13. Define selected CheckBox... to answer String... using blocks as shown in image below.
* This will set the String answer according to the selected CheckBox, and uncheck other three CheckBoxes.

14. Add CheckBox onClick event for all the four CheckBoxes.

In each of these CheckBox onClick events put blocks as shown below.
15. In the event button1 onClick, put following blocks.

* These blocks will increase score if answer is correct,
* display the score in textview4,
* save the score and FinishActivity on 10th question,
* or uncheck all checkBoxes, set String answer to..(empty), and pick a new question.

16. Save and run the project. The Quiz app is ready.
https://youtu.be/bk74fXQHTk8
The same method can be used to create a Firebase based Quiz app, if the Json data is uploaded to Firebase and retrieved to ListMap in onChildAdded event.
https://youtu.be/-KxcPE6BlIw