Previous Question
Next Question
Submit Quiz
//Question1
//Define Variables
var onep, oneL, oner, oneE
//Assigns Random Integers
do {
onep = (Math.floor(Math.random()*15)+8)*50 - (Math.floor(Math.random()*15)+8)*50;
}
while (onep == 0);
oneL = (Math.floor(Math.random()*12)+6)*2;
oner = Math.floor(Math.random()*6)+1;
oneE = 29000;
//find stress, strain, deformation
onearea = Math.PI*oner*oner;
onesigma = onep/onearea;
onestrain = onesigma/oneE;
onedelta = onestrain*oneL;
//Answer Choices
onecorrectanswer = "sigma = " + onesigma.toFixed(1).replace(/\.?0+$/,"").toString() + " ksi, epsilon = " + Math.abs(onestrain).toFixed(5).replace(/\.?0+$/,"").toString() + ", delta = " + onedelta.toFixed(3).replace(/\.?0+$/,"").toString() + " in.";
oneanswer1 = "sigma = " + -onesigma.toFixed(1).replace(/\.?0+$/,"").toString() + " ksi, epsilon = " + Math.abs(onestrain).toFixed(5).replace(/\.?0+$/,"").toString() + ", delta = " + onedelta.toFixed(3).replace(/\.?0+$/,"").toString() + " in.";
oneanswer2 = "sigma = " + onesigma.toFixed(1).replace(/\.?0+$/,"").toString() + " ksi, epsilon = " + Math.abs(onestrain).toFixed(5).replace(/\.?0+$/,"").toString() + ", delta = " + -onedelta.toFixed(3).replace(/\.?0+$/,"").toString() + " in.";
oneanswer3 = "sigma = " + -onesigma.toFixed(1).replace(/\.?0+$/,"").toString() + " ksi, epsilon = " + Math.abs(onestrain).toFixed(5).replace(/\.?0+$/,"").toString() + ", delta = " + -onedelta.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 stress, strain and deformation of the circular bar shown below this quiz where P = " + onep.toString() + " kips, L = " + oneL.toString() + " in, r = " + oner.toString() + " in, and E = 29000 ksi. Use + for Tension (Stress) and elongation (deformation)."
//Question2
//Define Variables
var twoT, twoL, twor, twoG
//Assigns Random Integers
twoT = (Math.floor(Math.random()*10)+1)*50;
twoL = (Math.floor(Math.random()*12)+6)*2;
twor = Math.floor(Math.random()*6)+1;
twoG = 11500;
//find stress, phi
twoJ = Math.PI*Math.pow(twor,4)/2;
twotau = twoT*twor/twoJ;
twophi = twoT*twoL/(twoG*twoJ);
twotau1 = twoT*twor*twor/twoJ;
twophi1 = twoT*twoL/(twoG*twoJ);
twotau2 = twoT*twor/twoJ;
twophi2 = twoT*twoL*twor/(twoG*twoJ);
twotau3 = twoT*twor*twor/twoJ;
twophi3 = twoT*twoL*twor/(twoG*twoJ);
//Answer Choices
//correct answer
twocorrectanswer = twotau.toFixed(3).replace(/\.?0+$/,"").toString() + " ksi, " + twophi.toFixed(3).replace(/\.?0+$/,"").toString() + " degrees."
twoanswer1 = twotau1.toFixed(3).replace(/\.?0+$/,"").toString() + " ksi, " + twophi1.toFixed(3).replace(/\.?0+$/,"").toString() + " degrees."
twoanswer2 = twotau2.toFixed(3).replace(/\.?0+$/,"").toString() + " ksi, " + twophi2.toFixed(3).replace(/\.?0+$/,"").toString() + " degrees."
twoanswer3 = twotau3.toFixed(3).replace(/\.?0+$/,"").toString() + " ksi, " + twophi3.toFixed(3).replace(/\.?0+$/,"").toString() + " degrees."
//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 shear stress and angle of twist for the bar shown below this quiz where T = " + twoT.toString() + " k-ft, r = " + twor.toString() + " in, L = " +twoL.toString() + " in, and G = 11500 ksi."
//Question3
//define variables
var threeL, threew, threebase, threeh
//Assign Random Integers
threeL = (Math.floor(Math.random()*5)+1)*5;
threew = Math.floor(Math.random()*11)+1;
threebase = Math.floor(Math.random()*6)+1;
threeh = Math.floor(Math.random()*11)+1;
//find stress
threemaxM = threew*threeL*threeL*12/8;
threemaxV = threew*threeL/2;
threeI = threebase*threeh*threeh*threeh/12;
threeQ = threebase*(threeh/2)*(threeh/4);
threesigma = threemaxM*(threeh/2)/threeI;
threetau = threemaxV*threeQ/(threeI*threebase);
threeI1 = threeh*threebase*threebase*threebase/12;
threeQ1 = threebase*threeh/4;
threesigma1 = threemaxM*(threeh/2)/threeI;
threetau1 = threemaxV*threeQ1/(threeI1*threebase);
threesigma2 = threemaxM*(threeh/2)/threeI1;
threetau2 = threemaxV*threeQ/(threeI*threebase);
threesigma3 = threemaxM*(threeh/2)/threeI1;
threetau3 = threemaxV*threeQ1/(threeI1*threebase);
//Answer Choices
//Correct Answer
threecorrectanswer = "sigma = " + threesigma.toString() + " ksi, tau = " + threetau.toString() + " ksi"
threeanswer1 = "sigma = " + threesigma1.toString() + " ksi, tau = " + threetau1.toString() + " ksi"
threeanswer2 = "sigma = " + threesigma2.toString() + " ksi, tau = " + threetau2.toString() + " ksi"
threeanswer3 = "sigma = " + threesigma3.toString() + " ksi, tau = " + threetau3.toString() + " ksi"
//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. Find the maximum bending stress and maximum shear stress for the beam shown below this quiz where L = " + threeL.toString() + " ft, w = " + threew.toString() + " k/ft, b = " + threebase.toString() + " in, and h = " + threeh.toString() + " in."
//Qestion4
//define variables
var fourT1, fourT2, fourL
//Assign Random Integers
do {
fourT1 = (Math.floor(Math.random()*20)+10)*5;
fourT2 = (Math.floor(Math.random()*20)+10)*5;
}
while (fourT1 > fourT2);
fourL = Math.floor(Math.random()*24)+12;
fouralpha = 13.1*Math.pow(10,-6);
fourE = 10000;
//find stress, strain, def
fourepsilon = fouralpha*(fourT2-fourT1);
foursigma = fourE*fourepsilon;
fourdelta = fourepsilon*fourL;
fourepsilon1 = fouralpha*(fourT1);
foursigma1 = fourE*fourepsilon1;
fourdelta1 = fourepsilon1*fourL;
fourepsilon2 = fouralpha*(fourT2);
foursigma2 = fourE*fourepsilon2;
fourdelta2 = fourepsilon2*fourL;
fourepsilon3 = fouralpha*(fourT2-fourT1)/2;
foursigma3 = fourE*fourepsilon3;
fourdelta3 = fourepsilon3*fourL;
//Answer Choices
fourcorrectanswer = "sigma = " + foursigma.toFixed(1).replace(/\.?0+$/,"").toString() + " ksi, epsilon = " + fourepsilon.toFixed(5).replace(/\.?0+$/,"").toString() + ", delta = " + fourdelta.toFixed(3).replace(/\.?0+$/,"").toString() + " in.";
fouranswer1 = "sigma = " + foursigma1.toFixed(1).replace(/\.?0+$/,"").toString() + " ksi, epsilon = " + fourepsilon1.toFixed(5).replace(/\.?0+$/,"").toString() + ", delta = " + fourdelta1.toFixed(3).replace(/\.?0+$/,"").toString() + " in.";
fouranswer2 = "sigma = " + foursigma2.toFixed(1).replace(/\.?0+$/,"").toString() + " ksi, epsilon = " + fourepsilon2.toFixed(5).replace(/\.?0+$/,"").toString() + ", delta = " + fourdelta2.toFixed(3).replace(/\.?0+$/,"").toString() + " in.";
fouranswer3 = "sigma = " + foursigma3.toFixed(1).replace(/\.?0+$/,"").toString() + " ksi, epsilon = " + fourepsilon3.toFixed(5).replace(/\.?0+$/,"").toString() + ", delta = " + fourdelta3.toFixed(3).replace(/\.?0+$/,"").toString() + " in.";
//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. A " + fourL.toString() + " in long, solid bar is heated from " + fourT1.toString() + " degrees F. to " +fourT2.toString() + " degrees F. Determine the stress, strain, and deformation where alpha = 13.1*10^-6/degree F. and E = 10,000 ksi"
//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
}
];
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.