1

I'M getting these error in javascript and it's driving me crazy I have looked over and over the code, i see nothing wrong I wanted to see if can get a fresh pair of eyes on this: I looked and looked at the code so much that I think I'm going cross-eyed

Okay i fix it now i'm getting this error XML Parsing Error: syntax error Location: file:///Volumes/YOLLIEBLUES/JS.finalProject/question.json Line Number 1, Column 1

SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 24 column 62 of the JSON data
[Learn More]
trivia.js:16:16
loadQuestions/test.onreadystatechange
file:///Volumes/YOLLIEBLUES/JS.finalProject/trivia.js:16:16


XML Parsing Error: syntax error
Location: file:///Volumes/YOLLIEBLUES/JS.finalProject/question.json
Line Number 1, Column 1:

Okay I fix that too but I'm still getting that error

XML Parsing Error: syntax error
Location: file:///Volumes/YOLLIEBLUES/JS.finalProject/question.json
Line Number 1, Column 1:

Im using firefox as my browers

"use strict";


let quizContainer = document.getElementById('quiz');
let resultContainer = document.getElementById('result');
let submitButton = document.getElementById('submit');

let myObj = "";
loadQuestions();

function loadQuestions() {
  let test = new XMLHttpRequest();
  test.open("Get", "question.json", true);
  test.onreadystatechange = function() {
    if (test.readyState == 4 && test.status == 200) {
      let myObj = JSON.parse(test.responseText);
      buildQuiz();
    }
  }
  test.send();
}

function buildQuiz() {
  for (var i in myObj) {
    console.log(myObj[i].question);
  }

}




//submitButton.addEventListener('click', showResults);

[
       {
            "title":"Superman is known as the world's greatest superhero. His alter-ego, Clark Kent, is a mild-mannered reporter for which newspaper?",
            "choices":[
                "The Daily Bugle",
                "The Gotham Gazette",
                "The Daily Planet",
                "The Central City Citizen"
            ],
            "correctAnswer":2
        },
        {
            "title":"John Constantine is a magician, demon-fighter, and all around do-gooder, but he's got one pretty serious vice. What is it?",
            "choices":[
                "Gambling",
                "Overeating",
                "Shoplifting",
                "Cigarettes"
            
            ],
            "correctAnswer":3
        },
        {
            "title": "She may be green, but she's got no reason to be jealous of anyone. In what universe is Guardian Gamora? ",
            "choices":[
                "Marvel",
                "Image",
                "Vertigo",
                "Top Shelf"
            ],
            "correctAnswer":0
        },
        {
            "title":"What is Peter Parker's middle name?",
            "choices":[
                "William",
                "Bartholomew",
                "Murdock",
                "Benjamin"
            ],
            "correctAnswer":3
        },
        {
            "title":"In honor of the Marvel's Infinity War comic book and movie coming out(You should really read the comic book soooo epic),Which villain possessed the Infinity Gems?",
            "choices":[
                "Galactus",
                "The Watchers",
                "Thanos",
                "Uatu"
            ],
            "correctAnswer":2
        },
        {
            "title":"Who paralyzed Barbara Gordon?",
            "choices":[
                "Two-Face",
                "ScareCrow",
                "The Joker (My husband to be)",
                "Solomon Grundy"
            ],
            "correctAnswer":2
        },
        {
            "title":"What is Batman Incorporated?",
            "choices":[
                "Army of Bat-Bot's",
                "Global crime-fighting organization"
            ],
            "correctAnswer":1
        },
        {
            "title":"Who is X-23?",
            "choices":[
                "New advanced Sentinel",
                "Wolverine's mutant clone"
            ],
            "correctAnswer":1
        },
        {
            "title":"Which book does Hermione steal from Dumbledore's office?",
            "choices":[
                "Magick Moste Evile",
                "The Tales of Beedle the Bard",
                "History of Magic",
                "Nature's Nobility: a Wizarding Genealogy"
            ],
            "correctAnswer":0
        },
        {
            "title":"Who disguised himself as Mad Eye Moody in the TheGoblet of Fire?",
            "choices":[
                "Barty Crouch Jr.",
                "Ernie McMillian",
                "Severus Snape",
                "Vincent Crabbe"
            ],
            "correctAnswer":0
        },{
            "title":"Han Solo's trusty blaster is a:?",
            "choices":[
                "D4-66",
                "BB-88",
                "DL-44"
            ],
            "correctAnswer":3
        },{
            "title":"Vader cuts off Luke's _____ hand?",
            "choices":[
                "right",
                "left",
                "both"
            ],
            "correctAnswer":0
        }
    ]
J.keve
  • 23
  • 5
  • error suggests line 24 of the json is at fault `"title":"I'm a warrior, an assassin. I don't dance." "She may be green, but she's got no reason to be jealous of anyone. In what universe is Guardian Gamora? ",` yep, looks wrong to me (check your quotes `"` ) – Jaromanda X Nov 30 '17 at 02:36
  • Okay i fix it now i'm getting this error XML Parsing Error: syntax error Location: file:///Volumes/YOLLIEBLUES/JS.finalProject/question.json Line Number 1, Column 1: – J.keve Nov 30 '17 at 02:41
  • What's `this.responseText`? Shouldn't it be `test.responseText`? – Alejandro Iván Nov 30 '17 at 02:49
  • I fix that too but I'm still getting that error XML Parsing Error: syntax error Location: file:///Volumes/YOLLIEBLUES/JS.finalProject/question.json Line Number 1, Column 1 – J.keve Nov 30 '17 at 02:53
  • I'm guessing but did you remove those `**` from your code? You should also check the HTTP status response code: `if ( test.readyState == 4 && test.status == 200 )` – Alejandro Iván Nov 30 '17 at 02:59
  • yes I did and I add what you suggested but I'm still getting this error XML Parsing Error: syntax error Location: file:///Volumes/YOLLIEBLUES/JS.finalProject/question.json Line Number 1, Column 1: – J.keve Nov 30 '17 at 03:04

1 Answers1

0

Go through the following Stack overflow post to escape the double quotes within values. Javascript Escape Double Quotes

Nagaraja Malla
  • 144
  • 1
  • 10