Previous QuestionNext QuestionSubmit Quiz
//Question1
//Define Variables
var onem, onems
//Assigns Random Integers
onew = Math.ceil((Math.floor(Math.random()*45)+75)*9.81);
onewm = onew + 100;
//find mass
onem = onew/9.81;
onem1 = onewm/9.81;
onem2 = onew/32.2*9.81;
onem3 = onewm/32.2*9.81;
//Answer Choices
onecorrectanswer = onem.toFixed(0).replace(/\.?0+$/,"").toString() + " kg";
oneanswer1 = onem1.toFixed(0).replace(/\.?0+$/,"").toString() + " kg";
oneanswer2 = onem2.toFixed(0).replace(/\.?0+$/,"").toString() + " kg";
oneanswer3 = onem3.toFixed(0).replace(/\.?0+$/,"").toString() + " kg";
//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. A man is in an elevator. When the elevator is at rest he weighs " + onew.toString() + " N. When the elevator begins to move he weighs " + onewm.toString() + " N. Determine the man's mass."
//Question2
//Define Variables
var twomu, twom, twotheta, twoP
//Assigns Random Integers
twomu = (Math.floor(Math.random()*4)+1)*0.1;
twom = (Math.floor(Math.random()*10)+5)*10;
twotheta = (Math.floor(Math.random()*7)+2)*5;
twoP = (Math.floor(Math.random()*20)+50)*10;
//find acceleration
twoNorm = (twom*9.81) - (twoP*Math.sin(twotheta*Math.PI/180));
twoax = ((twoP*Math.cos(twotheta*Math.PI/180)) - (twomu*twoNorm))/twom;
twoax1 = ((twoP*Math.cos(twotheta*Math.PI/180)) + (twomu*twoNorm))/twom;
twoax2 = ((twoP*Math.cos(twotheta*Math.PI/180)) - (twomu*twoNorm))/twoP;
twoax3 = ((twoP*Math.cos(twotheta*Math.PI/180)) - (twomu*((twom*9.81) + (twoP*Math.sin(twotheta*Math.PI/180)))))/twom;
//Answer Choices
twocorrectanswer = twoax.toFixed(2).replace(/\.?0+$/,"").toString() + " m/s^2"
twoanswer1 = twoax1.toFixed(2).replace(/\.?0+$/,"").toString() + " m/s^2"
twoanswer2 = twoax2.toFixed(2).replace(/\.?0+$/,"").toString() + " m/s^2"
twoanswer3 = twoax3.toFixed(2).replace(/\.?0+$/,"").toString() + " m/s^2"
//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. For a block being pulled along a horizontal surface with a coefficient of friction of " + twomu.toString() + ". If the block has a mass of " + twom.toString() + " kg. Determine the horizontal acceleration of the block shown below if theta = " + twotheta.toString() + " degrees and P = " + twoP.toString() + " N."
//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(
``
);
}
// 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);
Advertisements
error: Content is protected !!
Cookie Consent
We use cookies to improve your experience on our site. By using our site, you consent to cookies.
Registers a unique ID to keep statistics of what videos from YouTube the user has seen.
Session
DEVICE_INFO
Used to detect if the visitor has accepted the marketing category in the cookie banner. This cookie is necessary for GDPR-compliance of the website.
179 days
LOGIN_INFO
This cookie is used to play YouTube videos embedded on the website.
2 years
VISITOR_PRIVACY_METADATA
Youtube visitor privacy metadata cookie
180 days
GPS
Registers a unique ID on mobile devices to enable tracking based on geographical GPS location.
1 day
VISITOR_INFO1_LIVE
Tries to estimate the users' bandwidth on pages with integrated YouTube videos. Also used for marketing
179 days
PREF
This cookie stores your preferences and other information, in particular preferred language, how many search results you wish to be shown on your page, and whether or not you wish to have Google’s SafeSearch filter turned on.