First Commit
This commit is contained in:
35
INFO-1272 (JS 1)/Notes/Final/index.html
Normal file
35
INFO-1272 (JS 1)/Notes/Final/index.html
Normal file
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>INFO-1272 Final Notes</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>INFO-1272 Final Notes</h1>
|
||||
|
||||
<fieldset>
|
||||
<legend>Setup Quiz</legend>
|
||||
<label for="studentName">Student Name:</label><br>
|
||||
<input type="text" name="studentName" id="studentName" placeholder="Enter your name"><br>
|
||||
|
||||
<label for="numQuestions">Number of questions:</label><br>
|
||||
<input type="number" name="numQuestions" id="numQuestions" placeholder="Number of questions"><br>
|
||||
|
||||
<button id="startBtn">Start</button>
|
||||
</fieldset>
|
||||
|
||||
<div id="quizArea" style="display: none;">
|
||||
<p id="currentStudent"></p>
|
||||
<p id="question"></p>
|
||||
<input type="text" id="answerInput">
|
||||
<button id="submitAnswer">Submit</button>
|
||||
<p id="feedback"></p>
|
||||
</div>
|
||||
<div id="results"></div>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
239
INFO-1272 (JS 1)/Notes/Final/index.js
Normal file
239
INFO-1272 (JS 1)/Notes/Final/index.js
Normal file
@@ -0,0 +1,239 @@
|
||||
// for (var count = 0; count <= 5; count++) {
|
||||
// console.log("This is count: " + count);
|
||||
// }
|
||||
|
||||
// for (var count = 0; count < 7; count += 2) {
|
||||
// console.log("This is count: " + count);
|
||||
// }
|
||||
|
||||
// for (var count = 10; count >= 0; count--) {
|
||||
// console.log("This is count: " + count);
|
||||
// }
|
||||
|
||||
// console.log(Math.round(4.6666666));
|
||||
// console.log(Math.ceil(4.6666666));
|
||||
// console.log(Math.min(0, 100));
|
||||
|
||||
// function sumArray(arr) {
|
||||
// var sum = 0;
|
||||
// for (var i = 0; i < arr.length; i++) {
|
||||
// sum += arr[i];
|
||||
// }
|
||||
// return sum;
|
||||
// }
|
||||
|
||||
// function reverseString(inString) {
|
||||
// var outString = "";
|
||||
// for (var i = inString.length - 1; i >= 0; i--) {
|
||||
// outString += inString[i];
|
||||
// }
|
||||
// return outString;
|
||||
// }
|
||||
|
||||
// function printMessage() {
|
||||
// var userInput = document.getElementById("textInput").value;
|
||||
// console.log("You entered: ", userInput);
|
||||
// }
|
||||
|
||||
// function currentTime() {
|
||||
// var now = new Date();
|
||||
// console.log(now.toLocaleDateString());
|
||||
// }
|
||||
|
||||
// function randomArray(arr) {
|
||||
// var numElements = 10;
|
||||
// for (var i = 0; i < numElements; i++) {
|
||||
// arr.push(Math.floor(Math.random() * 100) + 1);
|
||||
// }
|
||||
// return arr;
|
||||
// }
|
||||
|
||||
// var testArr = [1,2,3,4,5];
|
||||
// var total = sumArray(testArr);
|
||||
// console.log(total);
|
||||
|
||||
// console.log(reverseString("Penis"));
|
||||
|
||||
// // printMessage();
|
||||
// currentTime();
|
||||
// console.log(randomArray(testArr));
|
||||
|
||||
// var testDate = new Date();
|
||||
// console.log(testDate.getDate()); // DAY OF MONTH
|
||||
// console.log(testDate.getDay()); // DAY OF WEEK
|
||||
// console.log(testDate.getFullYear());
|
||||
// console.log(testDate.getMonth()); // STARTS AT 0
|
||||
// console.log(testDate.getTime());
|
||||
// console.log(testDate.getHours());
|
||||
|
||||
// function dateSlashes() {
|
||||
// var date = new Date();
|
||||
// var day = date.getDate();
|
||||
// var month = date.getMonth() + 1;
|
||||
// var year = date.getFullYear()
|
||||
// console.log(month + "/" + day + "/" + year);
|
||||
// }
|
||||
|
||||
// function dateSlashesReverse() {
|
||||
// var date = new Date();
|
||||
// var day = date.getDate();
|
||||
// var month = date.getMonth() + 1;
|
||||
// var year = date.getFullYear()
|
||||
// console.log(year + "/" + month + "/" + day);
|
||||
// }
|
||||
|
||||
// function monthWords () {
|
||||
// var date = new Date();
|
||||
// var day = date.getDate();
|
||||
// var monthNames = [
|
||||
// "January", "February", "March", "April", "May", "June",
|
||||
// "July", "August", "September", "October", "November", "December"
|
||||
// ]
|
||||
// var month = monthNames[date.getMonth()];
|
||||
// var year = date.getFullYear();
|
||||
// console.log(month + " " + day + ", " + year);
|
||||
// }
|
||||
|
||||
// function monthWordsLong () {
|
||||
// var date = new Date();
|
||||
// var dayNames = [
|
||||
// "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
|
||||
// ]
|
||||
// var weekDay = dayNames[date.getDay()];
|
||||
// var day = date.getDate();
|
||||
// var monthNames = [
|
||||
// "January", "February", "March", "April", "May", "June",
|
||||
// "July", "August", "September", "October", "November", "December"
|
||||
// ]
|
||||
// var month = monthNames[date.getMonth()];
|
||||
// var year = date.getFullYear();
|
||||
// console.log(weekDay + ", " + month + " " + day + ", " + year);
|
||||
// }
|
||||
|
||||
// function printTime() {
|
||||
// var date = new Date();
|
||||
// var hour = date.getHours();
|
||||
// var minutes = date.getMinutes();
|
||||
// if (minutes < 10) {
|
||||
// minutes = "0" + date.getMinutes();
|
||||
// }
|
||||
// console.log(hour + ":" + minutes);
|
||||
// }
|
||||
|
||||
// function printTime12Hr() {
|
||||
// var date = new Date();
|
||||
// var hour = date.getHours();
|
||||
// var minutes = date.getMinutes();
|
||||
// if (minutes < 10) {
|
||||
// minutes = "0" + minutes;
|
||||
// }
|
||||
// var half = hour < 12 ? "AM" : "PM";
|
||||
|
||||
// hour = hour % 12;
|
||||
// if (hour === 0) {
|
||||
// hour = 12;
|
||||
// }
|
||||
|
||||
// console.log(hour + ":" + minutes + " " + half);
|
||||
// }
|
||||
|
||||
// dateSlashes();
|
||||
// dateSlashesReverse();
|
||||
// monthWords();
|
||||
// monthWordsLong();
|
||||
// printTime();
|
||||
// printTime12Hr();
|
||||
|
||||
// switch(expression) {
|
||||
// case x: // can be anything really
|
||||
// //thing to do
|
||||
// break;
|
||||
// case y:
|
||||
// //different thing to do
|
||||
// break;
|
||||
// default:
|
||||
// //default behaviour
|
||||
// break; // without break, the program will execute the following cases
|
||||
// }
|
||||
|
||||
// person = {
|
||||
// name: "Undefined",
|
||||
// age: 0
|
||||
// };
|
||||
|
||||
// function Person(name, age) {
|
||||
// this.name = name;
|
||||
// this.age = age;
|
||||
// }
|
||||
|
||||
// console.log(person);
|
||||
// var people = [new Person("Levi", 20), new Person("Tyler", 20), new Person("Stu", 19), new Person("Andrew", 21)]
|
||||
// console.log(people);
|
||||
|
||||
function Student(name) {
|
||||
this.name = name;
|
||||
this.score = 0;
|
||||
}
|
||||
|
||||
function generateQuestions() {
|
||||
for (let i = 0; i < numQuestions; i++) {
|
||||
const q = generateRandomQuestion();
|
||||
console.log(q.question, q.answer);
|
||||
document.getElementById("question").textContent = q.question;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function generateRandomQuestion() {
|
||||
const operators = ["+", "-", "*", "/"];
|
||||
const operator = operators[Math.floor(Math.random() * operators.length)];
|
||||
var num1 = Math.floor(Math.random() * 20) + 1;
|
||||
var num2 = Math.floor(Math.random() * 20) + 1;
|
||||
|
||||
if (operator === "/") {
|
||||
num1 = num1 * num2;
|
||||
}
|
||||
|
||||
const questionStr = `${num1} ${operator} ${num2}`;
|
||||
var answer;
|
||||
|
||||
switch(operator) {
|
||||
case "+":
|
||||
answer = num1 + num2;
|
||||
break;
|
||||
case "-":
|
||||
answer = num1 - num2;
|
||||
break;
|
||||
case "*":
|
||||
answer = num1 * num2;
|
||||
break;
|
||||
case "/":
|
||||
answer = num1 / num2;
|
||||
break;
|
||||
}
|
||||
|
||||
return { question: questionStr, answer: answer };
|
||||
}
|
||||
|
||||
var currentStudent = null;
|
||||
var numQuestions = 0;
|
||||
var currentQuestion = 0;
|
||||
|
||||
document.getElementById("startBtn").addEventListener("click", function() {
|
||||
const nameInput = document.getElementById("studentName").value.trim();
|
||||
const numInput = parseInt(document.getElementById("numQuestions").value);
|
||||
|
||||
if (nameInput === "" || isNaN(numInput) || numInput <= 0) {
|
||||
alert("Please enter a valid name and a number of questions above 0.");
|
||||
return;
|
||||
}
|
||||
|
||||
currentStudent = new Student(nameInput);
|
||||
numQuestions = numInput;
|
||||
currentQuestion = 1;
|
||||
|
||||
document.getElementById("quizArea").style.display = "block";
|
||||
document.getElementById("currentStudent").textContent = "Student: " + currentStudent.name;
|
||||
|
||||
generateQuestions();
|
||||
});
|
||||
9
INFO-1272 (JS 1)/Notes/Final/index2.html
Normal file
9
INFO-1272 (JS 1)/Notes/Final/index2.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<head>
|
||||
<title>Index 2 Final Notes</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Index 2 Final Notes</h1>
|
||||
<script src="index2.js"></script>
|
||||
</body>
|
||||
97
INFO-1272 (JS 1)/Notes/Final/index2.js
Normal file
97
INFO-1272 (JS 1)/Notes/Final/index2.js
Normal file
@@ -0,0 +1,97 @@
|
||||
function Student(name, age, grade) {
|
||||
this.name = name,
|
||||
this.age = age,
|
||||
this.grade = grade
|
||||
};
|
||||
|
||||
function Car(brand, model, year, isElectric) {
|
||||
this.brand = brand,
|
||||
this.model = model,
|
||||
this.year = year,
|
||||
this.isElectric = isElectric,
|
||||
this.describe = function() {
|
||||
console.log(`This is a ${this.year} ${this.brand} ${this.model}`);
|
||||
}
|
||||
};
|
||||
|
||||
function House(type, bedrooms, price) {
|
||||
this.type = type;
|
||||
this.bedrooms = bedrooms;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
function Employee(name, position, salary) {
|
||||
this.name = name,
|
||||
this.position = position,
|
||||
this.salary = salary,
|
||||
this.increaseSalary = function(amount) {
|
||||
this.salary += amount;
|
||||
}
|
||||
}
|
||||
|
||||
function Movie(title, genre, rating) {
|
||||
this.title = title,
|
||||
this.genre = genre,
|
||||
this.rating = rating,
|
||||
this.rateMovie = function(newRating) {
|
||||
this.rating = newRating;
|
||||
}
|
||||
}
|
||||
|
||||
function Course(courseName, instructor, schedule) {
|
||||
this.courseName = courseName;
|
||||
this.instructor = instructor;
|
||||
this.schedule = schedule;
|
||||
}
|
||||
|
||||
var student1 = new Student("Levi McLean", 20, 99);
|
||||
var student2 = new Student("Tyler Hird", 19, 88);
|
||||
var student3 = new Student("Joe Jefferson", 21, 75);
|
||||
|
||||
var car1 = new Car("Tesla", "Model 3", 2025, true);
|
||||
var car2 = new Car("Ford", "F-150", 2020, false);
|
||||
|
||||
var house1 = new House("Bungalow", 2, 250000);
|
||||
var house2 = new House("Town House", 3, 375000);
|
||||
|
||||
var employee1 = new Employee("Jimmy Joe", "Manager", 80000);
|
||||
|
||||
var movie1 = new Movie("Kill Bill", "Action", 4.4);
|
||||
var movie2 = new Movie("Star Wars", "Action", 3.7);
|
||||
|
||||
console.log(student1.name + " " + student1.grade);
|
||||
console.log(student2.name + " " + student2.grade);
|
||||
console.log(student3.name + " " + student3.grade);
|
||||
|
||||
if (car1.isElectric === true) {
|
||||
console.log(`${car1.brand} ${car1.model} is an electric car!`)
|
||||
} if (car2.isElectric === true) {
|
||||
console.log(`${car2.brand} ${car2.model} is an electric car!`)
|
||||
}
|
||||
|
||||
car1.describe();
|
||||
car2.describe();
|
||||
|
||||
console.log(`The ${house1.type} has ${house1.bedrooms} bedrooms and costs $${house1.price}`);
|
||||
console.log(`The ${house2.type} has ${house2.bedrooms} bedrooms and costs $${house2.price}`);
|
||||
|
||||
console.log(`Previous ${employee1.position} salary: $${employee1.salary}.`);
|
||||
console.log("Increasing salary by $1000000");
|
||||
employee1.increaseSalary(1000000);
|
||||
console.log(`New ${employee1.position} salary: $${employee1.salary}.`);
|
||||
|
||||
console.log(`Previous rating for ${movie1.title}: ${movie1.rating}`);
|
||||
console.log(`Previous rating for ${movie2.title}: ${movie2.rating}`);
|
||||
movie1.rateMovie(5);
|
||||
console.log(`New rating for ${movie1.title}: ${movie1.rating}`);
|
||||
console.log(`New rating for ${movie2.title}: ${movie2.rating}`);
|
||||
|
||||
var courseSchedule = {
|
||||
day: "Monday",
|
||||
time: "10:00 AM",
|
||||
location: "Room 101"
|
||||
};
|
||||
|
||||
var course1 = new Course("JavaScript 1", "Mr. Smith", courseSchedule);
|
||||
|
||||
console.log(`The ${course1.courseName} course is taught by ${course1.instructor} on ${course1.schedule.day} at ${course1.schedule.time} in ${course1.schedule.location}`)
|
||||
Reference in New Issue
Block a user