Previous Question
Next Question
Submit Quiz
Engineering Economics Quiz
Back
Next
Submit
Reload
//Question1
//Define Variables
var onet1, onet2, onet3
//Assigns Random Integers
onet1 = (Math.floor(Math.random()*50)+1)*100;
onet2 = (Math.floor(Math.random()*30)+1)*100;
onet3 = (Math.floor(Math.random()*20)+1)*100;
//find profit/loss
onepl = onet1-onet2-onet3;
onepl1 = onet1+onet2+onet3;
onepl2 = -onet1+onet2+onet3;
onepl3 = -onet1-onet2-onet3;
//Answer Choices
if (onepl >= 0) {
onecorrectanswer = "$" + onepl.toString();
}
else {
onecorrectanswer = "-$" + -onepl.toString();
}
if (onepl1 >= 0) {
oneanswer1 = "$" + onepl1.toString();
}
else {
oneanswer1 = "-$" + -onepl1.toString();
}
if (onepl2 >= 0) {
oneanswer2 = "$" + onepl2.toString();
}
else {
oneanswer2 = "-$" + -onepl2.toString();
}
if (onepl3 >= 0) {
oneanswer3 = "$" + onepl3.toString();
}
else {
oneanswer3 = "-$" + -onepl3.toString();
}
//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. For a cash flow, determine the profit/loss at t = 3. Use t1 = $" + onet1.toString() + ", t2 = $" + onet2.toString() + ", t3 = $" + onet3.toString() + "."
//Question2
//Define Variables
var twopw, twoi, twon
//Assigns Random Integers
twopw = (Math.floor(Math.random()*30)+10)*1000;
twoi = Math.floor(Math.random()*7)+3;
twon = (Math.floor(Math.random()*6)+1)*5;
//find FW
twofw = twopw*Math.pow(1+(twoi/100),twon);
twofw1 = twopw*Math.pow(1-(twoi/100),twon);
twofw2 = twopw*Math.pow(1+(twoi/100),twon-1);
twofw3 = twopw*Math.pow(1+(twoi/100),twon/12);
//Answer Choices
//correct answer
twocorrectanswer = "$" + twofw.toFixed(2).toString();
twoanswer1 = "$" + twofw1.toFixed(2).toString();
twoanswer2 = "$" + twofw2.toFixed(2).toString();
twoanswer3 = "$" + twofw3.toFixed(2).toString();
//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. If $" + twopw.toString() + " is deposited into an account with a " + twoi.toString() + "% interest rate compounded annually. How much will the money be worth in " + twon.toString() + " years?"
//Question3
//define variables
var threean, threei, threen
//Assign Random Integers
threean = (Math.floor(Math.random()*10)+1)*100;
threei = Math.floor(Math.random()*7)+3;
threen = (Math.floor(Math.random()*6)+1)*5;
//find FW
threefw = threean*((Math.pow(1+(threei/100),threen)-1)/(threei/100));
threefw1 = threean*((Math.pow(1+(threei/100),threen)+1)/(threei/100));
threefw2 = threean*((Math.pow(1-(threei/100),threen)+1)/(threei/100));
threefw3 = threean*((Math.pow(1+(threei/100),threen/12)-1)/(threei/100));
//Answer Choices
threecorrectanswer = "$" + threefw.toFixed(2).toString();
threeanswer1 = "$" + threefw1.toFixed(2).toString();
threeanswer2 = "$" + threefw2.toFixed(2).toString();
threeanswer3 = "$" + threefw3.toFixed(2).toString();
//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. $" + threean.toString() + " is deposited at the end of each year into an account earning " + threei.toString() + "% interest. What amount will be accumulated in the account at the end of " + threen.toString() + " years?"
//Qestion4
//define variables
var fouran, fouri, fourn
//Assign Random Integers
fouran = (Math.floor(Math.random()*10)+1)*100;
fouri = Math.floor(Math.random()*10)+1;
fourn = (Math.floor(Math.random()*6)+1)*5;
//find PW
fourpw = fouran*((Math.pow(1+fouri/100,fourn)-1)/(fouri/100*Math.pow(1+fouri/100,fourn)));
fourpw1 = fouran*((Math.pow(1+fouri/100,fourn)+1)/(fouri/100*Math.pow(1+fouri/100,fourn)));
fourpw2 = fouran*((Math.pow(1+fouri/100,fourn/12)-1)/(fouri/100*Math.pow(1+fouri/100,fourn)));
fourpw3 = fouran*((Math.pow(1+fouri/100,fourn)-1)/(fouri/100*Math.pow(1+fouri/100,fourn/12)));
//Answer Choices
fourcorrectanswer = "$" + fourpw.toFixed(2).toString();
fouranswer1 = "$" + fourpw1.toFixed(2).toString();
fouranswer2 = "$" + fourpw2.toFixed(2).toString();
fouranswer3 = "$" + fourpw3.toFixed(2).toString();
//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 sum of money is deposited into a fund at " + fouri.toString() + "% interest. If $" + fouran.toString() + " is withdrawon at the end of each year for " + fourn.toString() + " years leaving nothing in the fund. Find the original amount deposited."
//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.