Previous Question
Next Question
Submit Quiz
//Question1
//Define Variables
var onet, oneL1, oneL2, oneL3
//Assigns Random Integers
onet = (Math.floor(Math.random()*4)+1)*0.25;
do {
oneL1 = (Math.floor(Math.random()*5)+1);
oneL2 = (Math.floor(Math.random()*5)+1);
oneL3 = (Math.floor(Math.random()*5)+1);
}
while (oneL1 >= oneL2 || oneL1 <= oneL3 || oneL2 <= oneL3)
//find centroid
onextilA = oneL1/2;
oneytilA = oneL2+(3*onet/2);
oneareaA = oneL1*onet;
onextilB = oneL1 + 0.5*onet;
oneytilB = (oneL2+2*onet)/2;
oneareaB = onet*(oneL2+2*onet);
onextilC = oneL1+onet+(oneL3/2);
oneytilC = onet/2;
oneareaC = oneL3*onet;
onexbarnum = (onextilA*oneareaA) + (onextilB*oneareaB) + (onextilC*oneareaC);
onexbardenom = oneareaA + oneareaB + oneareaC;
onexbar = onexbarnum/onexbardenom;
oneybarnum = (oneytilA*oneareaA) + (oneytilB*oneareaB) + (oneytilC*oneareaC);
oneybardenom = oneareaA + oneareaB + oneareaC;
oneybar = oneybarnum/oneybardenom;
onexbar2 = (onextilA+onextilB+onextilC)/onexbardenom;
oneybar2 = (oneytilA+oneytilB+oneytilC)/oneybardenom;
//Answer Choices
onecorrectanswer = "(" + onexbar.toFixed(3).replace(/\.?0+$/,"").toString() + " in, " + oneybar.toFixed(3).replace(/\.?0+$/,"").toString() + " in)"
oneanswer1 = "(" + oneybar.toFixed(3).replace(/\.?0+$/,"").toString() + " in, " + onexbar.toFixed(3).replace(/\.?0+$/,"").toString() + " in)"
oneanswer2 = "(" + onexbar2.toFixed(3).replace(/\.?0+$/,"").toString() + " in, " + oneybar2.toFixed(3).replace(/\.?0+$/,"").toString() + " in)"
oneanswer3 = "(" + oneybar2.toFixed(3).replace(/\.?0+$/,"").toString() + " in, " + onexbar2.toFixed(3).replace(/\.?0+$/,"").toString() + " in)"
//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
question1 = "1. Determine the centroid (from the datum) of the object shown below where t = " + onet.toString() + " in, L1 = " + oneL1.toString() + " in, L2 = " + oneL2.toString() + " in, and L3 = " + oneL3.toString() + " in."
//Question2
//Define Variables
var twot, twoL1, twoL2
//Assigns Random Integers
twot = (Math.floor(Math.random()*8)+1)*0.25
twoL1 = (Math.floor(Math.random()*13)+5);
twoL2 = (Math.floor(Math.random()*13)+5);
//find Ix and Iy
twobxA = twoL1;
twohxA = twot;
twobyA = twot;
twohyA = twoL1;
twoIpxA = twoL1*Math.pow(twot,3)/12;
twoIpyA = twot*Math.pow(twoL1,3)/12;
twoareaA = twoL1*twot;
twodxA = twoL2+0.5*twot;
twodyA = twoL1/2;
twoIxA = twoIpxA + twoareaA*twodxA*twodxA;
twoIyA = twoIpyA + twoareaA*twodyA*twodyA;
twobxB = twot;
twohxB = twoL2;
twobyB = twoL2;
twohyB = twot;
twoIpxB = twot*Math.pow(twoL2,3)/12;
twoIpyB = twoL2*Math.pow(twot,3)/12;
twoareaB = twoL2*twot;
twodxB = twoL2/2;
twodyB = twoL1/2;
twoIxB = twoIpxB + twoareaB*twodxB*twodxB;
twoIyB = twoIpyB + twoareaB*twodyB*twodyB;
twoIx = twoIxA + twoIxB;
twoIy = twoIyA + twoIyA;
twoIxA2 = twoIpxA + twoareaA*twodxA;
twoIyA2 = twoIpyA + twoareaA*twodyA;
twoIxB2 = twoIpxB + twoareaB*twodxB;
twoIyB2 = twoIpyB + twoareaB*twodyB;
twoIx2 = twoIxA2 + twoIxB2;
twoIy2 = twoIyA2 + twoIyA2;
//Answer Choices
twocorrectanswer = "Ix = " + twoIx.toFixed(1).replace(/\.?0+$/,"").toString() + " in^4, Iy = " + twoIy.toFixed(1).replace(/\.?0+$/,"").toString() + " in^4";
twoanswer1 = "Ix = " + twoIy.toFixed(1).replace(/\.?0+$/,"").toString() + " in^4, Iy = " + twoIx.toFixed(1).replace(/\.?0+$/,"").toString() + " in^4";
twoanswer2 = "Ix = " + twoIx2.toFixed(1).replace(/\.?0+$/,"").toString() + " in^4, Iy = " + twoIy2.toFixed(1).replace(/\.?0+$/,"").toString() + " in^4";
twoanswer3 = "Ix = " + twoIy2.toFixed(1).replace(/\.?0+$/,"").toString() + " in^4, Iy = " + twoIx2.toFixed(1).replace(/\.?0+$/,"").toString() + " in^4";
//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
question2 = "2. Determine the moments of inertia, Ix and Iy of the object shown below about the x-axis and y-axis shown where t = " + twot.toString() + " in, L1 = " + twoL1.toString() + " in, and L2 = " + twoL2.toString() + " in."
//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
}
];
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);
Quiz Image
You must be logged in to post a comment.