Previous Question
Next Question
Submit Quiz
//Question1
//Define Variables
var onew, onetheta, onemu
//Assigns Random Integers
onew = (Math.floor(Math.random()*6)+1)*10;
do {
onetheta = (Math.floor(Math.random()*12)+1)*5;
}
while (onetheta == 45);
onemu = (Math.floor(Math.random()*5)+1)*0.1.toFixed(1);
//find mu
onemuim = Math.sin(onetheta*Math.PI/180)/Math.cos(onetheta*Math.PI/180);
onemuim1 = -onemuim;
//find theta
onethetaim = Math.atan(onemu)*180/Math.PI;
onethetaim1 = Math.atan(1/onemu)*180/Math.PI;
//Answer Choices
onecorrectanswer = "Coeff. of Static Friction = " + onemuim.toFixed(2).replace(/\.?0+$/,"").toString() + ", theta = " + onethetaim.toFixed(1).replace(/\.?0+$/,"").toString() + " degrees"
oneanswer1 = "Coeff. of Static Friction = " + onemuim1.toFixed(2).replace(/\.?0+$/,"").toString() + ", theta = " + onethetaim.toFixed(1).replace(/\.?0+$/,"").toString() + " degrees"
oneanswer2 = "Coeff. of Static Friction = " + onemuim.toFixed(2).replace(/\.?0+$/,"").toString() + ", theta = " + onethetaim1.toFixed(1).replace(/\.?0+$/,"").toString() + " degrees"
oneanswer3 = "Coeff. of Static Friction = " + onemuim1.toFixed(2).replace(/\.?0+$/,"").toString() + ", theta = " + onethetaim1.toFixed(1).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. Determine the coefficient of static friction for impending motion of a " + onew.toString() + " lb block on a " + onetheta.toString() + " degree inclined plane. Then, if the coefficient of static friction is " +onemu.toString() + " determine theta for impending motion. (See figure below)"
//Question2
//Define Variables
var twoh, twob1, twomu, twow
//Assigns Random Integers
twomu = ((Math.floor(Math.random()*5)+1)*0.1).toFixed(1);
twoh = (Math.floor(Math.random()*4)+5);
twob1 = (Math.floor(Math.random()*4)+1);
twow = (Math.floor(Math.random()*10)+1)*50;
//find P for tipping
twoptip = (3*twow*twob1)/(4*twoh);
//find P for sliding
twopslide = twomu*twow;
//find controlling p
twop = Math.min(twoptip, twopslide)
//Answer Choices
if (twoptip < twopslide) {
twocorrectanswer = twop.toFixed(1).replace(/\.?0+$/,"").toString() + " lbs, tipping"
}
else {
twocorrectanswer = twop.toFixed(1).replace(/\.?0+$/,"").toString() + " lbs, sliding"
}
if (twoptip < twopslide) {
twoanswer1 = twop.toFixed(1).replace(/\.?0+$/,"").toString() + " lbs, sliding"
}
else {
twoanswer1 = twop.toFixed(1).replace(/\.?0+$/,"").toString() + " lbs, tipping"
}
if (twoptip < twopslide) {
twoanswer2 = twopslide.toFixed(1).replace(/\.?0+$/,"").toString() + " lbs, tipping"
}
else {
twoanswer2 = twoptip.toFixed(1).replace(/\.?0+$/,"").toString() + " lbs, sliding"
}
if (twoptip < twopslide) {
twoanswer3 = twopslide.toFixed(1).replace(/\.?0+$/,"").toString() + " lbs, sliding"
}
else {
twoanswer3 = twoptip.toFixed(1).replace(/\.?0+$/,"").toString() + " lbs, tipping"
}
//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 force P for impending motion of the " + twow.toString() + " lb box shown in the figure below where h = " + twoh.toString() + " ft, b = " + twob1.toString() + " ft, and the coefficient of static friction = " + twomu.toString(); + "."
//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.