Previous Question
Next Question
Submit Quiz
//Question1
//Define Variables
var onevA, onevB, onevC, onealpha, onebeta
//Assigns Random Integers
onevA = Math.floor(Math.random()*11)+1;
onevB = Math.floor(Math.random()*11)+1;
onevC = Math.floor(Math.random()*11)+1;
onealpha = Math.floor(Math.random()*75)+10;
onebeta = Math.floor(Math.random()*75)+10;
//find resultant force
oneax = -onevA*Math.sin(onealpha*Math.PI/180);
oneay = onevA*Math.cos(onealpha*Math.PI/180);
onebx = onevB*Math.cos(onebeta*Math.PI/180);
oneby = onevB*Math.sin(onebeta*Math.PI/180);
onecx = 0;
onecy = -onevC;
oneRx = oneax + onebx + onecx;
oneRy = oneay + oneby + onecy;
oneR = Math.sqrt(Math.pow(oneRx,2) + Math.pow(oneRy,2));
oneR1 = oneRx + oneRy;
oneR2 = Math.sqrt(2*oneRx+2*oneRy);
oneR3 = oneRx*oneRx+oneRy*oneRy;
onetheta = Math.atan(oneRy/oneRx)*180/Math.PI;
onetheta1 = -Math.atan(oneRy/oneRx)*180/Math.PI;
onetheta2 = Math.atan(oneRx/oneRy)*180/Math.PI;
onetheta3 = -Math.atan(oneRx/oneRy)*180/Math.PI;
//Answer Choices
onecorrectanswer = "R = " + oneR.toFixed(3).replace(/\.?0+$/,"").toString() + " kips, theta = " + onetheta.toFixed(3).replace(/\.?0+$/,"").toString() + " degrees";
oneanswer1 = "R = " + oneR1.toFixed(3).replace(/\.?0+$/,"").toString() + " kips, theta = " + onetheta1.toFixed(3).replace(/\.?0+$/,"").toString() + " degrees";
oneanswer2 = "R = " + oneR2.toFixed(3).replace(/\.?0+$/,"").toString() + " kips, theta = " + onetheta2.toFixed(3).replace(/\.?0+$/,"").toString() + " degrees";
oneanswer3 = "R = " + oneR3.toFixed(3).replace(/\.?0+$/,"").toString() + " kips, theta = " + onetheta3.toFixed(3).replace(/\.?0+$/,"").toString() + " degrees";
//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. find the resultant force and direction of the system shown below for A = " + onevA.toString() + " kips, B = " + onevB.toString() + " kips, C = " + onevC.toString() + " kips, alpha = " + onealpha.toString() + " degrees, beta = " + onebeta.toString() + " degrees.";
//Question2
//Define Variables
var twoomega1, twoomega2, twopoint1, twoL1, twoL2, twoL3, twoL4
//Assigns Random Integers
twoomega1 = Math.floor(Math.random()*16)+1;
twoomega2 = Math.floor(Math.random()*16)+1;
twopoint1 = Math.floor(Math.random()*50)+1;
twoL1 = Math.floor(Math.random()*6)+1;
twoL2 = Math.floor(Math.random()*6)+1;
twoL3 = Math.floor(Math.random()*6)+1;
twoL4 = Math.floor(Math.random()*6)+1;
//equivalent force/location
twofw1 = 0.5*twoL1*twoomega1;
twofw2 = twoL3*twoomega2;
twofy = twofw1+twofw2+twopoint1;
twofy1 = 2*twofw1+twofw2+twopoint1
twofy2 = twofw1+twofw2-twopoint1
twofy3 = twofw1+0.5*twofw2+twopoint1
//Answer Choices
twocorrectanswer = twofy.toString() + " kips";
twoanswer1 = twofy1.toString() + " kips";
twoanswer2 = twofy2.toString() + " kips";
twoanswer3 = twofy3.toString() + " kips";
//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. Find the equivalent force acting on the beam shown below this quiz where L1 = " + twoL1.toString() + " ft, L2 = " + twoL2.toString() + " ft, L3 = " + twoL3.toString() + " ft, L4 = " + twoL4.toString() + " ft, w1 = " + twoomega1.toString() + " k/ft, w2 = " + twoomega2.toString() + " k/ft, p1 = " + twopoint1.toString() + " kips"
//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.