I'd like to import test.js
in main.js
,I suffered some following errors..
I totally confused how to fix it and how to export correctly..
SyntaxError: Unexpected token export
If someone has opinion,please let me know.
Thanks
test.js
export default class Test {
constructor(quizData){
this._quizzes = quizData.results;
this._correctAnswersNum = 0;
}
getNumOfQuiz(){
return this._quizzes.length;
}
}
main.js
import Test from './test.js';
// require('./quiz.js')
(()=>{
const url = "/quiz-data";
console.log("main.js was loaded");
fetch(url)
.then(json => { const quiz = new Quiz(json); })
.then(quiz => displayQuiz(quiz,1))
})();