Previous Question
Next Question
Submit Quiz
//Question1
//Define Variables
var oneax, oneay, oneaz
//Assigns Random Integers
do {
oneax = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
oneay = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
oneaz = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
}
while (oneax == 0 || oneay ==0 || oneaz == 0);
//find magnitude
onemag = Math.sqrt(Math.pow(oneax,2)+Math.pow(oneay,2)+Math.pow(oneaz,2));
onemag1 = Math.pow(Math.pow(oneax,2)+Math.pow(oneay,2)+Math.pow(oneaz,2),2/3);
onemag2 = Math.pow(Math.abs(oneax + oneay + oneaz),2/3);
onemag3 = Math.sqrt(Math.abs(Math.pow(oneax,2)-Math.pow(oneay,2)+Math.pow(oneaz,2)));
//Answer Choices
onecorrectanswer = onemag.toFixed(3).replace(/\.?0+$/,"").toString();
oneanswer1 = onemag1.toFixed(3).replace(/\.?0+$/,"").toString();
oneanswer2 = onemag2.toFixed(3).replace(/\.?0+$/,"").toString();
oneanswer3 = onemag3.toFixed(3).replace(/\.?0+$/,"").toString();
//Place Answer Choices into Array
oneanswerchoices = [oneanswer1, oneanswer2, oneanswer3, onecorrectanswer];
//Randomize Answer Choices
do {
var indexa = Math.floor(Math.random()*oneanswerchoices.length);
var indexb = Math.floor(Math.random()*oneanswerchoices.length);
}
while (indexb == indexa);
do {
var indexc = Math.floor(Math.random()*oneanswerchoices.length);
}
while (indexc == indexa || indexc == indexb);
do {
var indexd = Math.floor(Math.random()*oneanswerchoices.length);
}
while (indexd == indexa || indexd == indexb ||
indexd == indexc);
onea = oneanswerchoices[indexa];
oneb = oneanswerchoices[indexb];
onec = oneanswerchoices[indexc];
oned = oneanswerchoices[indexd];
if (indexa == 3) {
onecorrectchoice = "a"
}
if (indexb == 3) {
onecorrectchoice = "b"
}
if (indexc == 3) {
onecorrectchoice = "c"
}
if (indexd == 3) {
onecorrectchoice = "d"
}
//Qeustion 1 Question
if (oneay > 0 && oneaz > 0) {
question1 = "1. Find the magnitude of the vector A = " + oneax.toString() + "i + " + oneay.toString() + "j + " + oneaz.toString() + "k"
}
else if (oneay < 0 && oneaz < 0) {
question1 = "1. Find the magnitude of the vector A = " + oneax.toString() + "i " + oneay.toString() + "j " + oneaz.toString() + "k"
}
else if (oneay < 0 && oneaz > 0) {
question1 = "1. Find the magnitude of the vector A = " + oneax.toString() + "i " + oneay.toString() + "j + " + oneaz.toString() + "k"
}
else {
question1 = "1. Find the magnitude of the vector A = " + oneax.toString() + "i + " + oneay.toString() + "j " + oneaz.toString() + "k"
}
//Question2
//Define Variables
var twoax, twoay, towaz
//Assigns Random Integers
do {
twoax = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
twoay = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
twoaz = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
}
while (twoax == 0 || twoay == 0 || twoaz == 0);
//find magnitude
twomag = Math.sqrt(Math.pow(twoax,2) + Math.pow(twoay,2) + Math.pow(twoaz,2));
twoi = twoax/twomag;
twoj = twoay/twomag;
twok = twoaz/twomag;
//Answer Choices
//correct answer
if (twoj > 0 && twok > 0) {
twocorrectanswer = twoi.toFixed(3).replace(/\.?0+$/,"").toString() + "i+" + twoj.toFixed(3).replace(/\.?0+$/,"").toString() + "j+" + twok.toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else if (twoj > 0 && twok < 0) {
twocorrectanswer = twoi.toFixed(3).replace(/\.?0+$/,"").toString() + "i+" + twoj.toFixed(3).replace(/\.?0+$/,"").toString() + "j" + twok.toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else if (twoj < 0 && twok > 0) {
twocorrectanswer = twoi.toFixed(3).replace(/\.?0+$/,"").toString() + "i" + twoj.toFixed(3).replace(/\.?0+$/,"").toString() + "j+" + twok.toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else {
twocorrectanswer = twoi.toFixed(3).replace(/\.?0+$/,"").toString() + "i" + twoj.toFixed(3).replace(/\.?0+$/,"").toString() + "j" + twok.toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
//Answer1
if (-twoj > 0 && -twok > 0) {
twoanswer1 = -twoi.toFixed(3).replace(/\.?0+$/,"").toString() + "i+" + -twoj.toFixed(3).replace(/\.?0+$/,"").toString() + "j+" + -twok.toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else if (-twoj > 0 && -twok < 0) {
twoanswer1 = -twoi.toFixed(3).replace(/\.?0+$/,"").toString() + "i+" + -twoj.toFixed(3).replace(/\.?0+$/,"").toString() + "j" + -twok.toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else if (-twoj < 0 && -twok > 0) {
twoanswer1 = -twoi.toFixed(3).replace(/\.?0+$/,"").toString() + "i" + -twoj.toFixed(3).replace(/\.?0+$/,"").toString() + "j+" + -twok.toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else {
twoanswer1 = -twoi.toFixed(3).replace(/\.?0+$/,"").toString() + "i" + -twoj.toFixed(3).replace(/\.?0+$/,"").toString() + "j" + -twok.toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
//Answer2
if (twoj > 0 && twok > 0) {
twoanswer2 = (1/twoi).toFixed(3).replace(/\.?0+$/,"").toString() + "i+" + (1/twoj).toFixed(3).replace(/\.?0+$/,"").toString() + "j+" + (1/twok).toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else if (twoj > 0 && twok < 0) {
twoanswer2 = (1/twoi).toFixed(3).replace(/\.?0+$/,"").toString() + "i+" + (1/twoj).toFixed(3).replace(/\.?0+$/,"").toString() + "j" + (1/twok).toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else if (twoj < 0 && twok > 0) {
twoanswer2 = (1/twoi).toFixed(3).replace(/\.?0+$/,"").toString() + "i" + (1/twoj).toFixed(3).replace(/\.?0+$/,"").toString() + "j+" + (1/twok).toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else {
twoanswer2 = (1/twoi).toFixed(3).replace(/\.?0+$/,"").toString() + "i" + (1/twoj).toFixed(3).replace(/\.?0+$/,"").toString() + "j" + (1/twok).toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
//Answer3
if (-twoj > 0 && twok > 0) {
twoanswer3 = (1/twoi).toFixed(3).replace(/\.?0+$/,"").toString() + "i+" + (-1/twoj).toFixed(3).replace(/\.?0+$/,"").toString() + "j+" + (1/twok).toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else if (-twoj > 0 && twok < 0) {
twoanswer3 = (1/twoi).toFixed(3).replace(/\.?0+$/,"").toString() + "i+" + (-1/twoj).toFixed(3).replace(/\.?0+$/,"").toString() + "j" + (1/twok).toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else if (-twoj < 0 && twok > 0) {
twoanswer3 = (1/twoi).toFixed(3).replace(/\.?0+$/,"").toString() + "i" + (-1/twoj).toFixed(3).replace(/\.?0+$/,"").toString() + "j+" + (1/twok).toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
else {
twoanswer3 = (1/twoi).toFixed(3).replace(/\.?0+$/,"").toString() + "i" + (-1/twoj).toFixed(3).replace(/\.?0+$/,"").toString() + "j" + (1/twok).toFixed(3).replace(/\.?0+$/,"").toString() + "k"
}
//Place Answer Choices into Array
twoanswerchoices = [twoanswer1, twoanswer2, twoanswer3, twocorrectanswer];
//Randomize Answer Choices
do {
var indexa = Math.floor(Math.random()*twoanswerchoices.length);
var indexb = Math.floor(Math.random()*twoanswerchoices.length);
}
while (indexb == indexa);
do {
var indexc = Math.floor(Math.random()*twoanswerchoices.length);
}
while (indexc == indexa || indexc == indexb);
do {
var indexd = Math.floor(Math.random()*twoanswerchoices.length);
}
while (indexd == indexa || indexd == indexb ||
indexd == indexc);
twoa = twoanswerchoices[indexa];
twob = twoanswerchoices[indexb];
twoc = twoanswerchoices[indexc];
twod = twoanswerchoices[indexd];
if (indexa == 3) {
twocorrectchoice = "a"
}
if (indexb == 3) {
twocorrectchoice = "b"
}
if (indexc == 3) {
twocorrectchoice = "c"
}
if (indexd == 3) {
twocorrectchoice = "d"
}
//Question 2 Question
if (twoay > 0 && twoaz > 0) {
question2 = "2. Find the unit vector for the vector A =" + twoax.toString() + "i+" + twoay.toString() + "j+" + twoaz.toString() + "k"
}
else if (twoay > 0 && twoaz < 0) {
question2 = "2. Find the unit vector for the vector A =" + twoax.toString() + "i+" + twoay.toString() + "j" + twoaz.toString() + "k"
}
else if (twoay < 0 && twoaz > 0) {
question2 = "2. Find the unit vector for the vector A =" + twoax.toString() + "i" + twoay.toString() + "j+" + twoaz.toString() + "k"
}
else {
question2 = "2. Find the unit vector for the vector A =" + twoax.toString() + "i" + twoay.toString() + "j" + twoaz.toString() + "k"
}
//Question3
//define variables
var threeax, threeay, threeaz, threebx, threeby, threebz
//Assign Random Integers
do {
threeax = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
threeay = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
threeaz = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
threebx = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
threeby = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
threebz = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
}
while (threeax == 0 || threeay == 0 || threeaz == 0 || threebx == 0 || threeby == 0 || threebz == 0)
//find i, j, k
threei = threeax+threebx;
threej = threeay+threeby;
threek = threeaz+threebz;
//Answer Choices
//Correct Answer
if (threej > 0 && threek > 0) {
threecorrectanswer = "A+B = " + threei.toString() + "i+" + threej.toString() + "j+" + threek.toString() + "k"
}
else if (threej > 0 && threek < 0) {
threecorrectanswer = "A+B = " + threei.toString() + "i+" + threej.toString() + "j" + threek.toString() + "k"
}
else if (threej < 0 && threek > 0) {
threecorrectanswer = "A+B = " + threei.toString() + "i" + threej.toString() + "j+" + threek.toString() + "k"
}
else {
threecorrectanswer = "A+B = " + threei.toString() + "i" + threej.toString() + "j" + threek.toString() + "k"
}
//Answer1
if (-threej > 0 && -threek > 0) {
threeanswer1 = "A+B = " + -threei.toString() + "i+" + -threej.toString() + "j+" + -threek.toString() + "k"
}
else if (-threej > 0 && -threek < 0) {
threeanswer1 = "A+B = " + -threei.toString() + "i+" + -threej.toString() + "j" + -threek.toString() + "k"
}
else if (-threej < 0 && -threek > 0) {
threeanswer1 = "A+B = " + -threei.toString() + "i" + -threej.toString() + "j+" + -threek.toString() + "k"
}
else {
threeanswer1 = "A+B = " + -threei.toString() + "i" + -threej.toString() + "j" + -threek.toString() + "k"
}
//Answer2
threeanswer2 = "A+B = " + (threeax+threebx+threeay+threeby+threeaz+threebz).toString();
//Answer3
threeanswer3 = "A+B = " + Math.sqrt(Math.abs(threei+threej+threek)).toFixed(3).replace(/\.?0+$/,"").toString();
//Place Answer Choices into Array
threeanswerchoices = [threeanswer1, threeanswer2, threeanswer3, threecorrectanswer];
//Randomize Answer Choices
do {
var indexa = Math.floor(Math.random()*threeanswerchoices.length);
var indexb = Math.floor(Math.random()*threeanswerchoices.length);
}
while (indexb == indexa);
do {
var indexc = Math.floor(Math.random()*threeanswerchoices.length);
}
while (indexc == indexa || indexc == indexb);
do {
var indexd = Math.floor(Math.random()*threeanswerchoices.length);
}
while (indexd == indexa || indexd == indexb ||
indexd == indexc);
threea = threeanswerchoices[indexa];
threeb = threeanswerchoices[indexb];
threec = threeanswerchoices[indexc];
threed = threeanswerchoices[indexd];
if (indexa == 3) {
threecorrectchoice = "a"
}
if (indexb == 3) {
threecorrectchoice = "b"
}
if (indexc == 3) {
threecorrectchoice = "c"
}
if (indexd == 3) {
threecorrectchoice = "d"
}
//Question 3 Question
question3 = "3. What is the sum of Vector A and B where A = " + threeax.toString() + "i + " + threeay.toString() + "j + " + threeaz.toString() + "k and B = " + threebx.toString() + "i + " + threeby.toString() + "j + " + threebz.toString() + "k"
//Qestion4
//define variables
var fourax, fouray, fouraz, fourbx, fourby, fourbz
//Assign Random Integers
do {
fourax = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
fouray = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
fouraz = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
fourbx = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
fourby = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
fourbz = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
}
while (fouraz ==0 || fouray == 0 || fouraz == 0 || fourbx ==0 || fourby == 0 || fourbz == 0);
//find dot product
fourdp = (fourax*fourbx) + (fouray*fourby) + (fouraz*fourbz);
//Answer Choices
fourcorrectanswer = fourdp.toString();
fouranswer1 = ((fourax*fourbx) - (fouray*fourby) + (fouraz*fourbz)).toString();
fouranswer2 = (-(fourax*fourbx) - (fouray*fourby) - (fouraz*fourbz)).toString();
fouranswer3 = (-(fourax*fourbx) + (fouray*fourby) - (fouraz*fourbz)).toString();
//Place Answer Choices into Array
fouranswerchoices = [fouranswer1, fouranswer2, fouranswer3, fourcorrectanswer];
//Randomize Answer Choices
do {
var indexa = Math.floor(Math.random()*fouranswerchoices.length);
var indexb = Math.floor(Math.random()*fouranswerchoices.length);
}
while (indexb == indexa);
do {
var indexc = Math.floor(Math.random()*fouranswerchoices.length);
}
while (indexc == indexa || indexc == indexb);
do {
var indexd = Math.floor(Math.random()*fouranswerchoices.length);
}
while (indexd == indexa || indexd == indexb ||
indexd == indexc);
foura = fouranswerchoices[indexa];
fourb = fouranswerchoices[indexb];
fourc = fouranswerchoices[indexc];
fourd = fouranswerchoices[indexd];
if (indexa == 3) {
fourcorrectchoice = "a"
}
if (indexb == 3) {
fourcorrectchoice = "b"
}
if (indexc == 3) {
fourcorrectchoice = "c"
}
if (indexd == 3) {
fourcorrectchoice = "d"
}
//Qeustion 4 Question
question4 = "4. What is the Dot Product of A and B, where A = " + fourax.toString() + "i + " + fouray.toString() + "j + " + fouraz.toString() + "k and B = " + fourbx.toString() + "i + " + fourby.toString() + "j + " + fourbz.toString() + "k"
//Question5
//define variables
var fiveax, fiveay, fiveaz, fivebx, fiveby, fivebz
//Get Random Integers
do {
fiveax = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
fiveay = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
fiveaz = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
fivebx = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
fiveby = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
fivebz = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
}
while (fiveax == 0 || fiveay == 0 || fiveaz == 0 || fivebx == 0 || fiveby == 0 || fivebz == 0);
//find angle
fivemaga = Math.sqrt(Math.pow(fiveax,2)+Math.pow(fiveay,2)+Math.pow(fiveaz,2));
fivemagb = Math.sqrt(Math.pow(fivebx,2)+Math.pow(fiveby,2)+Math.pow(fivebz,2));
fivedp = (fiveax*fivebx) + (fiveay*fiveby) + (fiveaz*fivebz);
fivecorrect = fivedp/(fivemaga*fivemagb);
fiveangle = Math.acos(fivecorrect)*180/Math.PI;
//Answer Choices
fivecorrectanswer = fiveangle.toFixed(3).replace(/\.?0+$/,"").toString() + " degrees";
fiveanswer1 = (Math.asin(fivedp/(fivemaga*fivemagb))*180/Math.PI).toFixed(3).replace(/\.?0+$/,"").toString() + " degrees";
fiveanswer2 = (Math.atan((fivemaga*fivemagb)/fivedp)*180/Math.PI).toFixed(3).replace(/\.?0+$/,"").toString() + " degrees";
fiveanswer3 = (Math.atan(fivedp/(fivemaga*fivemagb))*180/Math.PI).toFixed(3).replace(/\.?0+$/,"").toString() + " degrees";
//Place Answers into Array
fiveanswerchoices = [fiveanswer1, fiveanswer2,fiveanswer3, fivecorrectanswer];
//Randomize Answer Choices
do {
var indexa = Math.floor(Math.random()*fiveanswerchoices.length);
var indexb = Math.floor(Math.random()*fiveanswerchoices.length);
}
while (indexb == indexa);
do {
var indexc = Math.floor(Math.random()*fiveanswerchoices.length);
}
while (indexc == indexa || indexc == indexb);
do {
var indexd = Math.floor(Math.random()*fiveanswerchoices.length);
}
while (indexd == indexa || indexd == indexb ||
indexd == indexc);
fivea = fiveanswerchoices[indexa];
fiveb = fiveanswerchoices[indexb];
fivec = fiveanswerchoices[indexc];
fived = fiveanswerchoices[indexd];
if (indexa == 3) {
fivecorrectchoice = "a"
}
if (indexb == 3) {
fivecorrectchoice = "b"
}
if (indexc == 3) {
fivecorrectchoice = "c"
}
if (indexd == 3) {
fivecorrectchoice = "d"
}
//Question 5 Question
question5 = "5. Find the angle between vector A and B where A = " + fiveax.toString() + "i + " + fiveay.toString() + "j + " + fiveaz.toString() + "k and B = " + fivebx.toString() + "i + " + fiveby.toString() + "j + " + fivebz.toString() + "k"
//Question6
//define variables
var sixax, sixay, sixaz, sixbx, sixby, sixbz
//Assign Random Variables
do {
sixax = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
sixay = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
sixaz = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
sixbx = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
sixby = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
sixbz = Math.floor(Math.random()*11) - Math.floor(Math.random()*11);
}
while (sixax == 0 || sixay == 0 || sixaz == 0 || sixbx == 0 || sixby == 0 || sixbz == 0);
//Find cross-product
sixi = (sixay*sixbz)-(sixby*sixaz);
sixj = -((sixax*sixbz)-(sixbx*sixaz));
sixk = (sixax*sixby)-(sixbx*sixay);
//Answer Choices
//correct answer
if (sixj > 0 && sixk > 0) {
sixcorrectanswer = sixi.toString() + "i+" + sixj.toString() + "j+" + sixk.toString() + "k"
}
else if (sixj > 0 && sixk < 0) {
sixcorrectanswer = sixi.toString() + "i+" + sixj.toString() + "j" + sixk.toString() + "k"
}
else if (sixj < 0 && sixk > 0) {
sixcorrectanswer = sixi.toString() + "i" + sixj.toString() + "j+" + sixk.toString() + "k"
}
else {
sixcorrectanswer = sixi.toString() + "i" + sixj.toString() + "j" + sixk.toString() + "k"
}
//answer1
if (-sixj > 0 && sixk > 0) {
sixanswer1 = sixi.toString() + "i+" + -sixj.toString() + "j+" + sixk.toString() + "k"
}
else if (-sixj > 0 && sixk < 0) {
sixanswer1 = sixi.toString() + "i+" + -sixj.toString() + "j" + sixk.toString() + "k"
}
else if (-sixj < 0 && sixk > 0) {
sixanswer1 = sixi.toString() + "i" + -sixj.toString() + "j+" + sixk.toString() + "k"
}
else {
sixanswer1 = sixi.toString() + "i" + -sixj.toString() + "j" + sixk.toString() + "k"
}
//answer2
if (-sixj > 0 && -sixk > 0) {
sixanswer2 = -sixi.toString() + "i+" + -sixj.toString() + "j+" + -sixk.toString() + "k"
}
else if (-sixj > 0 && -sixk < 0) {
sixanswer2 = -sixi.toString() + "i+" + -sixj.toString() + "j" + -sixk.toString() + "k"
}
else if (-sixj < 0 && -sixk > 0) {
sixanswer2 = -sixi.toString() + "i" + -sixj.toString() + "j+" + -sixk.toString() + "k"
}
else {
sixanswer2 = -sixi.toString() + "i" + -sixj.toString() + "j" + -sixk.toString() + "k"
}
//answer3
if (sixj > 0 && -sixk > 0) {
sixanswer3 = -sixi.toString() + "i+" + sixj.toString() + "j+" + -sixk.toString() + "k"
}
else if (sixj > 0 && -sixk < 0) {
sixanswer3 = -sixi.toString() + "i+" + sixj.toString() + "j" + -sixk.toString() + "k"
}
else if (sixj < 0 && -sixk > 0) {
sixanswer3 = -sixi.toString() + "i" + sixj.toString() + "j+" + -sixk.toString() + "k"
}
else {
sixanswer3 = -sixi.toString() + "i" + sixj.toString() + "j" + -sixk.toString() + "k"
}
//Place answers into Array
sixanswerchoices = [sixanswer1, sixanswer2, sixanswer3, sixcorrectanswer];
//Randomize Answer Choices
do {
var indexa = Math.floor(Math.random()*sixanswerchoices.length);
var indexb = Math.floor(Math.random()*sixanswerchoices.length);
}
while (indexb == indexa);
do {
var indexc = Math.floor(Math.random()*sixanswerchoices.length);
}
while (indexc == indexa || indexc == indexb);
do {
var indexd = Math.floor(Math.random()*sixanswerchoices.length);
}
while (indexd == indexa || indexd == indexb ||
indexd == indexc);
sixa = sixanswerchoices[indexa];
sixb = sixanswerchoices[indexb];
sixc = sixanswerchoices[indexc];
sixd = sixanswerchoices[indexd];
if (indexa == 3) {
sixcorrectchoice = "a"
}
if (indexb == 3) {
sixcorrectchoice = "b"
}
if (indexc == 3) {
sixcorrectchoice = "c"
}
if (indexd == 3) {
sixcorrectchoice = "d"
}
//Question 6 Question
question6 = "6. Find the cross product AXB, where A = " + sixax.toString() + "i + " + sixay.toString() + "j + " + sixaz.toString() + "k and B = " + sixbx.toString() + "i + " + sixby.toString() + "j + " + sixbz.toString() + "k"
//Question Slides
const myQuestions = [
{
question: question1,
answers: {
a: onea,
b: oneb,
c: onec,
d: oned
},
correctAnswer: onecorrectchoice
},
{
question: question2,
answers: {
a: twoa,
b: twob,
c: twoc,
d: twod
},
correctAnswer: twocorrectchoice
},
{
question: question3,
answers: {
a: threea,
b: threeb,
c: threec,
d: threed
},
correctAnswer: threecorrectchoice
},
{
question: question4,
answers: {
a: foura,
b: fourb,
c: fourc,
d: fourd
},
correctAnswer: fourcorrectchoice
},
{
question: question5,
answers: {
a: fivea,
b: fiveb,
c: fivec,
d: fived
},
correctAnswer: fivecorrectchoice
},
{
question: question6,
answers: {
a: sixa,
b: sixb,
c: sixc,
d: sixd
},
correctAnswer: sixcorrectchoice
}
];
function buildQuiz() {
// we'll need a place to store the HTML output
const output = [];
// for each question...
myQuestions.forEach((currentQuestion, questionNumber) => {
// we'll want to store the list of answer choices
const answers = [];
// and for each available answer...
for (letter in currentQuestion.answers) {
// ...add an HTML radio button
answers.push(
`
${letter} :
${currentQuestion.answers[letter]}
`
);
}
// add this question and its answers to the output
output.push(
`
${currentQuestion.question}
${answers.join("")}
`
);
});
// finally combine our output list into one string of HTML and put it on the page
quizContainer.innerHTML = output.join("");
}
function showResults() {
// gather answer containers from our quiz
const answerContainers = quizContainer.querySelectorAll(".answers");
// keep track of user's answers
let numCorrect = 0;
// for each question...
myQuestions.forEach((currentQuestion, questionNumber) => {
// find selected answer
const answerContainer = answerContainers[questionNumber];
const selector = `input[name=question${questionNumber}]:checked`;
const userAnswer = (answerContainer.querySelector(selector) || {}).value;
// if answer is correct
if (userAnswer === currentQuestion.correctAnswer) {
// add to the number of correct answers
numCorrect++;
// color the answers green
answerContainers[questionNumber].style.color = "green";
} else {
// if answer is wrong or blank
// color the answers red
answerContainers[questionNumber].style.color = "red";
}
});
// show number of correct answers out of total
resultsContainer.innerHTML = `${numCorrect} out of ${myQuestions.length}`;
}
function showSlide(n) {
slides[currentSlide].classList.remove("active-slide");
slides[n].classList.add("active-slide");
currentSlide = n;
if (currentSlide === 0) {
previousButton.style.display = "none";
} else {
previousButton.style.display = "inline-block";
}
if (currentSlide === slides.length - 1) {
nextButton.style.display = "none";
submitButton.style.display = "inline-block";
} else {
nextButton.style.display = "inline-block";
submitButton.style.display = "inline-block";
}
}
function showNextSlide() {
showSlide(currentSlide + 1);
}
function showPreviousSlide() {
showSlide(currentSlide - 1);
}
const quizContainer = document.getElementById("quiz");
const resultsContainer = document.getElementById("results");
const submitButton = document.getElementById("submit");
// display quiz right away
buildQuiz();
const previousButton = document.getElementById("previous");
const nextButton = document.getElementById("next");
const slides = document.querySelectorAll(".slide");
let currentSlide = 0;
showSlide(0);
// on submit, show results
submitButton.addEventListener("click", showResults);
previousButton.addEventListener("click", showPreviousSlide);
nextButton.addEventListener("click", showNextSlide);