Device Sync
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}`)
|
||||
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
@@ -173,4 +174,181 @@
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
|
||||
=======
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Midterm Study</title>
|
||||
<meta charset="utf-8" lang="en-us">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Midterm Study</h1>
|
||||
<h2>Introduction to Web Pages</h2>
|
||||
<ol>
|
||||
<li>A web page is a container for the following three technologies. Describe the purpose of each for a web page:
|
||||
</li>
|
||||
<ul>
|
||||
<li>HTML</li>
|
||||
<li>CSS</li>
|
||||
<li>JavaScript</li>
|
||||
</ul>
|
||||
</ol>
|
||||
<p>Answers:</p>
|
||||
<ul>
|
||||
<li>HTML is used for defining web elements and the rough layout of a website</li>
|
||||
<li>CSS is used to style the default HTML elements</li>
|
||||
<li>JavaScript is used for data input, manipulation and other logical components</li>
|
||||
</ul>
|
||||
<hr>
|
||||
|
||||
<h2>Introduction to javascript</h2>
|
||||
<ol>
|
||||
<li>Browser pop-up dialogue box functions</li>
|
||||
<ul>
|
||||
<li>alert()</li>
|
||||
<li>prompt()</li>
|
||||
<li>confirm()</li>
|
||||
</ul>
|
||||
</ol>
|
||||
<p>Answers:</p>
|
||||
<ul>
|
||||
<li>Reload webpage to see examples</li>
|
||||
</ul>
|
||||
<hr>
|
||||
|
||||
<h2>Data Types and Variables</h2>
|
||||
<ol>
|
||||
<li>Name JavaScript's three data types. Describe the types of data they store</li>
|
||||
<li>JavaScript is a weakly-typed language. Describe what this means.</li>
|
||||
<li>What are the naming rules for a variables name? What are naming conventions?</li>
|
||||
<li>What is a constant in JavaScript? Describe how you would declare a JavaScript constant.</li>
|
||||
</ol>
|
||||
<p>Answers:</p>
|
||||
<ol>
|
||||
<li>Number, String and Boolean</li>
|
||||
<li>weakly-typed language implies that data types do not need to be defined at initialization, the compiler will
|
||||
decide, cast and convert the data type unless explicitly cast</li>
|
||||
<li>A naming convention is a recommended way of naming variables to ensure readability and organize code.
|
||||
JavaScript uses camelCase for variables and classes and UPPER_SNAKE_CASE for constants</li>
|
||||
<code>
|
||||
let customerAge = 23;<br>
|
||||
const ONT_TAX_RATE = 0.13;
|
||||
</code>
|
||||
<li>A constant is a variable whose value cannot be changed once initialized, making it constant. To define a
|
||||
constant, use the "const" keyword.</li>
|
||||
</ol>
|
||||
<hr>
|
||||
|
||||
<h2>Operators</h2>
|
||||
<ol>
|
||||
<li>Explain the following binary operators: + - * / %</li>
|
||||
<li>Explain the multiple uses of the + operator.</li>
|
||||
<li>Describe how the increment/decrement operators (++ and --) work.</li>
|
||||
</ol>
|
||||
<p>Answers:</p>
|
||||
<ol>
|
||||
<li>The + operator is used to get the sum, the - operator is to get the difference, the * operator multiplies,
|
||||
the / operator divides and the % (modulus) operator determines if two numbers divided have a remainder and
|
||||
how much of one</li>
|
||||
<li>The + operator can be used to add two numbers together to find their sum, or you can use it to concatenate
|
||||
multiple Strings together.</li>
|
||||
<li>The ++ (increment) operator is used to increase the value of a variable by exactly one. The -- (decrement)
|
||||
operator is used to decrease the value of a variable by exactly 1.</li>
|
||||
</ol>
|
||||
<hr>
|
||||
|
||||
<h2>The JavaScript Math object</h2>
|
||||
<ol>
|
||||
<li>Describe the operation and the return for the following Math methods:</li>
|
||||
<ul>
|
||||
<li>Math.PI</li>
|
||||
<li>Math.abs(x)</li>
|
||||
<li>Math.pow(x,2)</li>
|
||||
<li>Math.round(x)</li>
|
||||
<li>Math.ceil(x)</li>
|
||||
<li>Math.floor(x)</li>
|
||||
<li>Math.trunc(x)</li>
|
||||
<li>Math.random()</li>
|
||||
<li>Math.min(x,y)</li>
|
||||
<li>Math.max(x,y)</li>
|
||||
</ul>
|
||||
</ol>
|
||||
<p>Answers:</p>
|
||||
<ul>
|
||||
<li>Math.PI is a constant value for PI</li>
|
||||
<li>Math.abs(x) returns the absolute value of X (makes a negative positive)</li>
|
||||
<li>Math.pow(x,2) returns the value of x to the power of y (in this case 2)</li>
|
||||
<li>Math.round(x) returns x rounded to the nearest whole. Below 0.5 is rounded down, above 0.5 is rouded up.
|
||||
</li>
|
||||
<li>Math.ceil(x) returns the "ceiling" of x, which is the next highest whole integer.</li>
|
||||
<li>Math.floor(x) returns the "floor" of x, which is the next lowest whole integer.</li>
|
||||
<li>Math.trunc(x) returns x truncated, which means it cuts off the decimal places regardless of what they are.
|
||||
</li>
|
||||
<li>Math.random() returns a random number between 0 and 1, can be manipulated to return in between any range
|
||||
</li>
|
||||
<li>Math.min(x,y) returns the minimum of two numbers. The smaller of the two</li>
|
||||
<li>Math.max(x,y) returns the maximum of two numbers. The larger of the two</li>
|
||||
</ul>
|
||||
<hr>
|
||||
|
||||
<h2>JavaScript Number Methods</h2>
|
||||
<ol>
|
||||
<li>Describe the operation and the return for the following Number methods:</li>
|
||||
<ul>
|
||||
<li>toFixed()</li>
|
||||
<li>toPrecision()</li>
|
||||
</ul>
|
||||
</ol>
|
||||
<p>Answers:</p>
|
||||
<ul>
|
||||
<li>toFixed() returns x but at a fixed number of decimal places, defined by y</li>
|
||||
<li>toPrecision() returns x but at a fixed number of significant digits. This means it may round deicimal places
|
||||
before dropping them.</li>
|
||||
</ul>
|
||||
<hr>
|
||||
|
||||
<h2>JavaScript Global Functions</h2>
|
||||
<ol>
|
||||
<li>Describe the operation and the return for the following global functions:</li>
|
||||
<ul>
|
||||
<li>parseInt(number)</li>
|
||||
<li>parseFloat(number)</li>
|
||||
</ul>
|
||||
</ol>
|
||||
<p>Answers:</p>
|
||||
<ul>
|
||||
<li>parseInt(number) takes a string as input and returns the first integer in the string. Can also accept a
|
||||
radix option</li>
|
||||
<li>parseFloat(number) takes a string as input and returns the first float value in the string.</li>
|
||||
</ul>
|
||||
<hr>
|
||||
|
||||
<h2>JavaScript String Methods</h2>
|
||||
<ol>
|
||||
<li>Describe the operation and the return for the following String methods.</li>
|
||||
<ul>
|
||||
<li>length</li>
|
||||
<li>toLowerCase()</li>
|
||||
<li>toUpperCase()</li>
|
||||
<li>charAt()</li>
|
||||
</ul>
|
||||
</ol>
|
||||
<p>Answers:</p>
|
||||
<ul>
|
||||
<li>length gets the character count of a string including spaces</li>
|
||||
<li>toLowerCase() turns all uppercase letters to lowercase letters</li>
|
||||
<li>toUpperCase() turns all lowercase letters to uppercase letters</li>
|
||||
<li>chatAt() takes a number for the index of the word to search through and returns the character at that index.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h2>Playground</h2>
|
||||
<p>Interactive JavaScript follows</p>
|
||||
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
|
||||
>>>>>>> a2ad5843006c62096be10203d3f91faa39f365fb
|
||||
</html>
|
||||
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
// for (var i = 1; i < 10; i++) {
|
||||
// console.log("Ran " + i + " time(s).")
|
||||
// };
|
||||
@@ -187,4 +188,195 @@ if (charCount >= 10 && numCount >= 3 && symCount >= 1) {
|
||||
window.alert("Your password is OKAY");
|
||||
} else {
|
||||
window.alert("Your password is WEAK");
|
||||
=======
|
||||
// for (var i = 1; i < 10; i++) {
|
||||
// console.log("Ran " + i + " time(s).")
|
||||
// };
|
||||
|
||||
// console.log(window.confirm("Feel prepared?")); // true or false
|
||||
|
||||
// var question = ("50" === 50);
|
||||
// console.log(question);
|
||||
|
||||
// var question2 = (true && false);
|
||||
// console.log(question2);
|
||||
|
||||
// var question3 = (true || false);
|
||||
// console.log(question3);
|
||||
|
||||
// // VAR price = 35.6; <-- WRONG
|
||||
// var price = 35.6; // <-- RIGHT
|
||||
|
||||
// var city = "London";
|
||||
|
||||
// if (city.toLowerCase() === "london") {
|
||||
// console.log("I live there too!");
|
||||
// } else {
|
||||
// console.log("I dont know where that is.")
|
||||
// }
|
||||
|
||||
// var userName = window.prompt("Please enter your name:");
|
||||
// greetUser(userName);
|
||||
|
||||
// var radius = window.prompt("Please enter circle radius:");
|
||||
// calcCirc(radius);
|
||||
|
||||
// var testNum = window.prompt("Number to test for even:");
|
||||
// isEven(testNum);
|
||||
|
||||
// function greetUser(userName) {
|
||||
// alert("Hello " + userName + " welcome to the page");
|
||||
// }
|
||||
|
||||
// function calcCirc(radius) {
|
||||
// var Circ = ((2 * Math.PI) * radius).toFixed(2);
|
||||
// alert("Circumference is: " + Circ + " Inches.");
|
||||
// }
|
||||
|
||||
// function isEven(number) {
|
||||
// if (number % 2 == 0) {
|
||||
// console.log(number + " is even");
|
||||
// } else {
|
||||
// console.log(number + " is odd");
|
||||
// }
|
||||
// }
|
||||
|
||||
// NUMBER GUESSING GAME
|
||||
// var randomNum = Math.floor((Math.random() * 100) + 1);
|
||||
// console.log("Random Number: " + randomNum);
|
||||
|
||||
// var userGuess;
|
||||
// do {
|
||||
// var input = window.prompt("Guess a number from 1-100: ");
|
||||
// if (input === null) {
|
||||
// window.alert("Game cancelled.");
|
||||
// break;
|
||||
// }
|
||||
|
||||
// userGuess = parseInt(input, 10);
|
||||
// if (isNaN(userGuess) || userGuess < 1 || userGuess > 100) {
|
||||
// window.alert("Please enter a valid number between 1 and 100.");
|
||||
// } else if (userGuess !== randomNum) {
|
||||
// window.alert("Incorrect number, try again!");
|
||||
// }
|
||||
// } while (userGuess !== randomNum);
|
||||
|
||||
// if (userGuess === randomNum) {
|
||||
// window.alert("You guessed the right number! The number was " + randomNum);
|
||||
// }
|
||||
|
||||
// ROCK PAPER SCISSORS GAME
|
||||
// var choices = ["rock", "paper", "scissors"];
|
||||
// var compChoice = choices[Math.floor(Math.random() * 3)];
|
||||
// console.log("Computer choice: " + compChoice);
|
||||
|
||||
// var userChoice = window.prompt("Enter rock, paper or scissors: ").toLowerCase();
|
||||
// console.log("User choice: " + userChoice);
|
||||
|
||||
// if (!choices.includes(userChoice)) {
|
||||
// window.alert("Invalid choice!");
|
||||
// } else if (userChoice === compChoice) {
|
||||
// window.alert("It's a tie!");
|
||||
// } else {
|
||||
// var winsAgainst = {
|
||||
// rock: "scissors",
|
||||
// paper: "rock",
|
||||
// scissors: "paper"
|
||||
// };
|
||||
|
||||
// if (winsAgainst[userChoice] === compChoice) {
|
||||
// window.alert("You win!");
|
||||
// } else {
|
||||
// window.alert("Computer wins!");
|
||||
// }
|
||||
// }
|
||||
|
||||
// SAMPLE BANK ACCOUNT
|
||||
// var bankBalance = 0;
|
||||
// console.log("Bank balance: $" + bankBalance);
|
||||
|
||||
// function getAmount(message) {
|
||||
// var input = window.prompt(message);
|
||||
// if (input === null) return null;
|
||||
// var amount = parseInt(input, 10);
|
||||
// if (isNaN(amount)) {
|
||||
// window.alert("Please enter a valid number.");
|
||||
// return null;
|
||||
// }
|
||||
// return amount;
|
||||
// }
|
||||
|
||||
// while (true) {
|
||||
// var userChoice = window.prompt(
|
||||
// "Welcome! Your bank balance is: $" + bankBalance +
|
||||
// ". Would you like to (w)ithdraw, (d)eposit or (v)iew balance, or (q)uit?");
|
||||
// if (userChoice === null || userChoice.toLowerCase() === "q") break;
|
||||
// userChoice = userChoice.toLowerCase();
|
||||
// console.log(userChoice);
|
||||
|
||||
// if (userChoice === "w" || userChoice === "withdrawl") {
|
||||
// var widthdrawlAmount = getAmount("How much would you like to widthdraw?");
|
||||
// if (widthdrawlAmount === null) continue;
|
||||
// if (widthdrawlAmount > bankBalance) {
|
||||
// window.alert("Not enough in balance to widthdraw, sorry!");
|
||||
// } else if (widthdrawlAmount <= 0) {
|
||||
// window.alert("Cannot widthdraw negative or 0 dollars.");
|
||||
// } else {
|
||||
// bankBalance -= widthdrawlAmount;
|
||||
// console.log("Bank balance: $" + bankBalance);
|
||||
// }
|
||||
// } else if (userChoice === "d" || userChoice === "deposit") {
|
||||
// var depositAmount = getAmount("How much would you like to deposit?");
|
||||
// if (depositAmount === null) continue;
|
||||
// if (depositAmount <= 0) {
|
||||
// window.alert("Cannot deposit negative or 0 dollars.");
|
||||
// } else {
|
||||
// bankBalance += depositAmount;
|
||||
// console.log("Bank balance: $" + bankBalance);
|
||||
// }
|
||||
// } else if (userChoice === "v" || userChoice === "view") {
|
||||
// window.alert("Your balance is: $" + bankBalance + " dollars. Thank you for banking with us!");
|
||||
// console.log("Bank balance: $" + bankBalance);
|
||||
// } else {
|
||||
// window.alert("Invalid choice, please try again");
|
||||
// }
|
||||
// }
|
||||
|
||||
// ARRAY STATS CALCULATOR
|
||||
// var stats = [];
|
||||
// var sum = 0;
|
||||
|
||||
// for (var i = 0; i < 50; i++) {
|
||||
// var randomNum = Math.floor(Math.random() * 50);
|
||||
// sum += randomNum;
|
||||
// stats.push(randomNum);
|
||||
// console.log(randomNum);
|
||||
// }
|
||||
// console.log(stats);
|
||||
|
||||
// console.log("Sum of stats: " + sum);
|
||||
// console.log("Average of stats: " + (sum / stats.length));
|
||||
// console.log("Min of stats: " + Math.min(...stats));
|
||||
// console.log("Max of stats: " + Math.max(...stats));
|
||||
|
||||
// PASSWORD STRENGTH CHECKER
|
||||
var userPass = window.prompt("Enter a password to test: ");
|
||||
var charCount, numCount, symCount;
|
||||
|
||||
charCount = userPass.length;
|
||||
console.log(charCount);
|
||||
|
||||
numCount = (userPass.match(/\d/g) || []).length;
|
||||
console.log(numCount);
|
||||
|
||||
symCount = (userPass.match(/[^a-zA-Z0-9]/g) || []).length;
|
||||
console.log(symCount);
|
||||
|
||||
if (charCount >= 10 && numCount >= 3 && symCount >= 1) {
|
||||
window.alert("Your password is STRONG");
|
||||
} else if (charCount >= 10 && numCount >= 1) {
|
||||
window.alert("Your password is OKAY");
|
||||
} else {
|
||||
window.alert("Your password is WEAK");
|
||||
>>>>>>> a2ad5843006c62096be10203d3f91faa39f365fb
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -31,4 +32,39 @@
|
||||
<button type="submit" id="repeatButton" onclick="repeatInfo()">Repeat Info</button>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
=======
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Week 1 Class 1</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Javascript test</h1>
|
||||
<script>
|
||||
document.write("Hello Class, Welcome to JavaScript <br>");
|
||||
document.write("I love JavaScript");
|
||||
|
||||
document.write("Hello Class, Welcome to JavaScript")
|
||||
document.write("<br>");
|
||||
document.write("I love JavaScript <br>");
|
||||
|
||||
window.alert("ALERT ALERT ALERT ALERT");
|
||||
window.confirm("CONFIRM PLEASE CONFIRM PLEASE");
|
||||
window.prompt("PROMPT HERE PROMPT HERE");
|
||||
</script>
|
||||
<button type="submit" id="testButton" onclick="testButton()">
|
||||
<p>Press me!</p>
|
||||
</button>
|
||||
<p id="buttonLabel">Button pressed!</p>
|
||||
<hr>
|
||||
<h2>Form example</h2>
|
||||
<input type="text" id="firstName" placeholder="First name">
|
||||
<input type="text" id="lastName" placeholder="Last name">
|
||||
<input type="email" id="email" placeholder="Email">
|
||||
<input type="text" id="phone" placeholder="Phone number">
|
||||
<p id="formLabel">You entered: </p>
|
||||
<button type="submit" id="repeatButton" onclick="repeatInfo()">Repeat Info</button>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
>>>>>>> a2ad5843006c62096be10203d3f91faa39f365fb
|
||||
</html>
|
||||
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
document.getElementById("buttonLabel").style.display = "none";
|
||||
|
||||
function testButton() {
|
||||
@@ -16,4 +17,24 @@ function repeatInfo() {
|
||||
const email = document.getElementById("email").value;
|
||||
const phone = Number(document.getElementById("phone").value);
|
||||
formLabel.innerHTML += `${firstName} ${lastName}, ${email}, ${phone}`
|
||||
=======
|
||||
document.getElementById("buttonLabel").style.display = "none";
|
||||
|
||||
function testButton() {
|
||||
const buttonLabel = document.getElementById("buttonLabel");
|
||||
if (buttonLabel.style.display === "block") {
|
||||
buttonLabel.style.display = "none";
|
||||
} else {
|
||||
buttonLabel.style.display = "block";
|
||||
}
|
||||
}
|
||||
|
||||
function repeatInfo() {
|
||||
const formLabel = document.getElementById("formLabel");
|
||||
const firstName = document.getElementById("firstName").value;
|
||||
const lastName = document.getElementById("lastName").value;
|
||||
const email = document.getElementById("email").value;
|
||||
const phone = Number(document.getElementById("phone").value);
|
||||
formLabel.innerHTML += `${firstName} ${lastName}, ${email}, ${phone}`
|
||||
>>>>>>> a2ad5843006c62096be10203d3f91faa39f365fb
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -15,4 +16,23 @@
|
||||
<p id="detailsLabel">Entered Details: </p>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
=======
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Week 3 Class 1</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Week 3 Class 1</h1>
|
||||
<p>Enter some details</p>
|
||||
<input id="firstNameBox" type="text" placeholder="First Name">
|
||||
<input id="lastNameBox" type="text" placeholder="Last Name">
|
||||
<input id="ageBox" type="number" placeholder="Age">
|
||||
<input id="passwordBox" type="password" placeholder="Password">
|
||||
<button type="submit" onclick="showDetails()">Submit</button>
|
||||
<p id="detailsLabel">Entered Details: </p>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
>>>>>>> a2ad5843006c62096be10203d3f91faa39f365fb
|
||||
</html>
|
||||
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
function showDetails() {
|
||||
var firstName = document.getElementById("firstNameBox").value;
|
||||
var lastName = document.getElementById("lastNameBox").value;
|
||||
@@ -11,4 +12,19 @@ function showDetails() {
|
||||
console.log(10 - 3);
|
||||
console.log(100 / 25);
|
||||
console.log(100 % 3);
|
||||
=======
|
||||
function showDetails() {
|
||||
var firstName = document.getElementById("firstNameBox").value;
|
||||
var lastName = document.getElementById("lastNameBox").value;
|
||||
var age = Number(document.getElementById("ageBox").value);
|
||||
var password = document.getElementById("passwordBox").value;
|
||||
console.log(`You entered: ${firstName}, ${lastName}, ${age}, ${password}`);
|
||||
document.getElementById("detailsLabel").innerHTML += `${firstName}, ${lastName}, ${age}, ${password}`;
|
||||
|
||||
console.log(10 + 10);
|
||||
console.log(10 * 10);
|
||||
console.log(10 - 3);
|
||||
console.log(100 / 25);
|
||||
console.log(100 % 3);
|
||||
>>>>>>> a2ad5843006c62096be10203d3f91faa39f365fb
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -8,4 +9,16 @@
|
||||
<h1>Week 8 JS Object Practice</h1>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
=======
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Week 8 JS Object Practice</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Week 8 JS Object Practice</h1>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
>>>>>>> a2ad5843006c62096be10203d3f91faa39f365fb
|
||||
</html>
|
||||
@@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
// Question 1
|
||||
function person(firstName, lastName, age, city) {
|
||||
return {
|
||||
@@ -61,3 +62,68 @@ console.log("Last Song");
|
||||
console.log(playlist.songs[playlist.songs.length - 1]); // Always get last entry
|
||||
|
||||
// Question 5
|
||||
=======
|
||||
// Question 1
|
||||
function person(firstName, lastName, age, city) {
|
||||
return {
|
||||
firstName: firstName,
|
||||
lastName: lastName,
|
||||
age: age,
|
||||
city: city
|
||||
};
|
||||
}
|
||||
|
||||
var testPerson = person("Levi", "McLean", 20, "Woodstock");
|
||||
console.log(testPerson.firstName);
|
||||
console.log(testPerson.lastName);
|
||||
console.log(testPerson.age);
|
||||
console.log(testPerson.city);
|
||||
|
||||
// Question 2
|
||||
function book(title, author, pages) {
|
||||
return {
|
||||
title: title,
|
||||
author: author,
|
||||
pages: pages
|
||||
};
|
||||
}
|
||||
|
||||
var testBook = book("1984", "George Orwell", 386);
|
||||
console.log(testBook.title);
|
||||
console.log(testBook.author);
|
||||
console.log(testBook.pages);
|
||||
console.log("Update pages to 555");
|
||||
testBook.pages = 555;
|
||||
console.log(testBook.pages);
|
||||
|
||||
// Question 3
|
||||
function movie(name, year, rating) {
|
||||
return {
|
||||
name: name,
|
||||
year: year,
|
||||
rating: rating
|
||||
};
|
||||
}
|
||||
|
||||
var testMovie = movie("Kill Bill", 2003, 9.5);
|
||||
console.log(testMovie.name);
|
||||
console.log(testMovie.year);
|
||||
console.log(testMovie.rating);
|
||||
console.log("Adding new property director");
|
||||
testMovie.director = "Quentin Tarantino";
|
||||
console.log(testMovie.director);
|
||||
|
||||
// Question 4
|
||||
const playlist = {
|
||||
name: "Cool Jams",
|
||||
songs: ["Rap song", "Metal song", "Pop song"]
|
||||
};
|
||||
|
||||
console.log(playlist.songs);
|
||||
console.log("First Song");
|
||||
console.log(playlist.songs[0]);
|
||||
console.log("Last Song");
|
||||
console.log(playlist.songs[playlist.songs.length - 1]); // Always get last entry
|
||||
|
||||
// Question 5
|
||||
>>>>>>> a2ad5843006c62096be10203d3f91faa39f365fb
|
||||
|
||||
Reference in New Issue
Block a user