Previous Question
Next Question
Submit Quiz
//Question1
//Define Variables
var oneomega1, onepoint1, oneL
//Assigns Random Integers
oneomega1 = Math.floor(Math.random()*10)+1;
onepoint1 = Math.floor(Math.random()*50)+1;
oneL = Math.floor(Math.random()*10)+5;
//find reactions
onefw1 = oneomega1*oneL/2;
oneRb = ((onefw1*oneL/4) + (onepoint1*((oneL/2)+(oneL/4))))/oneL;
oneRa = (onefw1+onepoint1) - oneRb;
oneRb1 = (onefw1*oneL/4) + (onepoint1*((oneL/2)+(oneL/4)));
oneRa1 = (onefw1+onepoint1) - oneRb1;
oneRb2 = ((onefw1) + (onepoint1*((oneL/2)+(oneL/4))))/oneL;
oneRa2 = (onefw1+onepoint1) - oneRb2;
oneRb3 = ((onefw1*oneL/4) + onepoint1)/oneL;
oneRa3 = (onefw1+onepoint1) - oneRb3;
//Answer Choices
onecorrectanswer = "RA = " + oneRa.toFixed(3).replace(/\.?0+$/,"").toString() + " kips, RB = " + oneRb.toFixed(3).replace(/\.?0+$/,"").toString() + " kips";
oneanswer1 = "RA = " + oneRa1.toFixed(3).replace(/\.?0+$/,"").toString() + " kips, RB = " + oneRb1.toFixed(3).replace(/\.?0+$/,"").toString() + " kips";
oneanswer2 = "RA = " + oneRa2.toFixed(3).replace(/\.?0+$/,"").toString() + " kips, RB = " + oneRb2.toFixed(3).replace(/\.?0+$/,"").toString() + " kips";
oneanswer3 = "RA = " + oneRa3.toFixed(3).replace(/\.?0+$/,"").toString() + " kips, RB = " + oneRb3.toFixed(3).replace(/\.?0+$/,"").toString() + " kips";
//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 reactions for the beam shown below this quiz where w1 = " + oneomega1.toString() + " k/ft, P1 = " + onepoint1.toString() + " kips, and the total length of the beam, L = " + oneL.toString() + " ft";
//Question2
//Define Variables
var twomoment1, twopoint1, twoL
//Assigns Random Integers
twomoment1 = Math.floor(Math.random()*50)+1;
twopoint1 = Math.floor(Math.random()*10)+1;
twoL = Math.floor(Math.random()*6)+1;
//find reactions
twoRya = twopoint1;
twoRma = twomoment1-twopoint1*twoL;
twoRya1 = -twopoint1;
twoRma1 = twomoment1-twopoint1*twoL;
twoRya2 = -twopoint1;
twoRma2 = -(twomoment1-twopoint1*twoL);
twoRya3 = twopoint1;
twoRma3 = -(twomoment1-twopoint1*twoL);
//Answer Choices
twocorrectanswer = "RYA = " + twoRya.toString() + " kips, RMA = " + twoRma.toString() + " k-ft";
twoanswer1 = "RYA = " + twoRya1.toString() + " kips, RMA = " + twoRma1.toString() + " k-ft";
twoanswer2 = "RYA = " + twoRya2.toString() + " kips, RMA = " + twoRma2.toString() + " k-ft";
twoanswer3 = "RYA = " + twoRya3.toString() + " kips, RMA = " + twoRma3.toString() + " k-ft";
//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 reactions for the beam shown below this quiz where M1 = " + twomoment1.toString() + " kip-ft, P1 = " + twopoint1.toString() + " kips, and the total lengthe of the beam, L = " + twoL.toString() + " ft"
//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.