Previous QuestionNext QuestionSubmit Quiz
//Question1
//Define Variables
var onem, onev, oner
//Assigns Random Integers
onem = (Math.floor(Math.random()*5)+1)*5;
onev = (Math.floor(Math.random()*4)+1)*5
oner = (Math.floor(Math.random()*10)+1)*0.1
//find kinetic energy
oneomega = onev/oner;
oneI = 0.5*onem*oner*oner;
oneTt = 0.5*onem*onev*onev;
oneTr = 0.5*oneI*oneomega*oneomega;
oneT = oneTt + oneTr;
oneT1 = 0.5*onem*onev + oneTr;
oneT2 = oneTt;
oneT3 = oneTr;
//Answer Choices
onecorrectanswer = oneT.toFixed(3).replace(/\.?0+$/,"").toString() + " J"
oneanswer1 = oneT1.toFixed(3).replace(/\.?0+$/,"").toString() + " J"
oneanswer2 = oneT2.toFixed(3).replace(/\.?0+$/,"").toString() + " J"
oneanswer3 = oneT3.toFixed(3).replace(/\.?0+$/,"").toString() + " J"
//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 " + onem.toString() + " kg disk is rolling along a flat surface at a rate of " + onev.toString() + " m/s. The disk has a radius of " + oner.toFixed(1).toString() + " m. Find the total kinetic energy of the disk."
//Question2
//Define Variables
var twok, twox
//Assigns Random Integers
twok = (Math.floor(Math.random()*5)+3)*100;
twox = (Math.floor(Math.random()*9)+1)*10;
//find potential energy
twoxm = twox/100;
twoU = 0.5*twok*twoxm*twoxm;
twoU1 = twok*twoxm*twoxm;
twoU2 = 0.5*twok*twoxm;
twoU3 = 100*twoxm*twoxm;
//Answer Choices
twocorrectanswer = twoU.toFixed(3).replace(/\.?0+$/,"").toString() + " J"
twoanswer1 = twoU1.toFixed(3).replace(/\.?0+$/,"").toString() + " J"
twoanswer2 = twoU2.toFixed(3).replace(/\.?0+$/,"").toString() + " J"
twoanswer3 = twoU3.toFixed(3).replace(/\.?0+$/,"").toString() + " J"
//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. What is the potential energy of a spring that is extended " + twox.toString() + " cm and has a spring constant of k = " + twok.toString() + " N/m."
//Question3
//Define Variables
var threem, threeh
//Assigns Random Integers
threem = (Math.floor(Math.random()*5)+1)*5;
threeh = (Math.floor(Math.random()*5)+1)*50;
//find velocity
threeT2 = 0.5*threem;
threeU1 = threem*9.81*threeh;
threev = Math.sqrt(threeU1/threeT2);
threev1 = Math.sqrt(threeU1);
threev2 = Math.sqrt(threem*9.81*threeh/threem);
threev3 = Math.sqrt(9.81*threeh/0.5*threem)
//Answer Choices
threecorrectanswer = threev.toFixed(3).replace(/\.?0+$/,"").toString() + " m/s"
threeanswer1 = threev1.toFixed(3).replace(/\.?0+$/,"").toString() + " m/s"
threeanswer2 = threev2.toFixed(3).replace(/\.?0+$/,"").toString() + " m/s"
threeanswer3 = threev3.toFixed(3).replace(/\.?0+$/,"").toString() + " m/s"
//Place Answer Choices into Array
threeanswerchoices = [threeanswer1, threeanswer2, threeanswer3, threecorrectanswer];
//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);
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. A " + threem.toString() + " kg weight is dropped from a height of " + threeh.toString() + " m. Neglecting air resistance, determine the velocity of the weight when it hits the ground."
//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
}
];
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 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.
10 years from set/ update
YSC
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.