@jesst446 wrote:
hi
I have created a simple quiz and for some reason it will not load to start the quiz
it comes up with this error in the console angular.js:30269WARNING: Tried to load angular more than once.
Here is the code :
quiz. js
var app = angular.module('quizApp', []);
app.directive('quiz', function(quizFactory) {
return {
restrict: 'AE',
scope: {},
templateUrl: 'quiz.html',
link: function(scope, elem, attrs) {
scope.start = function() {
scope.id = 0;
scope.quizOver = false;
scope.inProgress = true;
scope.getQuestion();
$compile($(element))(scope);
};scope.reset = function() { scope.inProgress = false; scope.score = 0; } scope.getQuestion = function() { var q = quizFactory.getQuestion(scope.id); if(q) { scope.question = q.question; scope.options = q.options; scope.answer = q.answer; scope.answerMode = true; } else { scope.quizOver = true; } }; scope.checkAnswer = function() { if(!$('input[name=answer]:checked').length) return; var ans = $('input[name=answer]:checked').val(); if(ans == scope.options[scope.answer]) { scope.score++; scope.correctAns = true; } else { scope.correctAns = false; } scope.answerMode = false; }; scope.nextQuestion = function() { scope.id++; scope.getQuestion(); } scope.reset(); } }
});
app.factory('quizFactory', function() {
var questions = [
{
question: "A doctor who can typically diagnose food allergies is called an allergist?",
options: ["True", "False"],
answer: 0
},
{
question: "Anaphylaxis should be treated with an antihistamine pill (e.g. Benadryl)?",
options: ["True", "False"],
answer: 1
},
{
question: "What's the best place for an allergic person to keep their auto-injector (e.g. EpiPen)?",
options: ["With them at all times", "In their car", "in their locker"],
answer: 0
},{ question: "If someone is having anaphylactic reaction, what is the correct emergency procedure to follow?", options: ["Give epi pen, call 999, use the second dose of epi pen if needed, go to the hospital", "Use epi pen, drive to hospital", "Take an anti-histamine e.g. Benadryl, call 999, use epi pen, go to the hospital"], answer: 0 }, { question: "Epiephrine auto-injectors i.e. EpiPen are not reusable and expire within approximately one year?", options: ["True", "False"], answer: 0 }, { question: "Anaphylaxis is caused by what system in the body?", options: ["The immune system", "The respiratory system", "The digestive system"], answer: 0 } ]; return { getQuestion: function(id) { if(id < questions.length) { return questions[id]; } else { return false; } } };
});
quiz. html file
http://codepen.io/anon/pen/wMYLBGindex.html
<!-- Quiz Js --> <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script> <script src="js/quiz.js"></script
please can you tell me where I am going wrong with this
thanks
Posts: 1
Participants: 1