Java Script and HTML
Variables, Functions, Arrays, IJavaScript HTML, using Jupyter Notebooks + Hacks
console.log("Hello, World!");
var msg = "Hello, World!";
console.log(msg);
function logIt(output) {
console.log(output);
}
logIt(msg);
console.log("Reuse!")
logIt("Hello, Students!");
logIt(2022)
function logItType(output) {
console.log(typeof output, ";", output);
}
console.log("Looking at dynamic nature of types in JavaScript")
logItType("Hi Class!"); // String
logItType(2022); // Number
logItType([1, 2, 3]);
// define a function to hold data for a Person
function Person(name, ghID, classOf) {
this.name = name;
this.ghID = ghID;
this.classOf = classOf;
this.role = "";
}
// define a setter for role in Person data
Person.prototype.setRole = function(role) {
this.role = role;
}
// define a JSON conversion "method" associated with Person
Person.prototype.toJSON = function() {
const obj = {name: this.name, ghID: this.ghID, classOf: this.classOf, role: this.role};
const json = JSON.stringify(obj); // json/string is useful when passing data on internet
return json;
}
// make a new Person and assign to variable teacher
var teacher = new Person("Mr M", "jm1021", 1977); // object type is easy to work with in JavaScript
logItType(teacher); // before role
logItType(teacher.toJSON()); // ok to do this even though role is not yet defined
// output of Object and JSON/string associated with Teacher
teacher.setRole("Teacher"); // set the role
logItType(teacher);
logItType(teacher.toJSON());
Hacks
Sample Calculator using HTML: https://hetvit27.github.io/hetvitrivedi/calculator/
- Used basic math like addition, subtraction, multiplication, and division and defined operations
- Used grids for design of the numbers
- Styled the calculator with color and pixels
- Another idea is that on the backend, I could've used a console that show a tab at the top of the page for outputs
//logging function
function logIt(output) {
console.log(output);
}
// define a function to hold data for a Person
function Name(age, grade, hobbies) {
this.age = age;
this.grade = grade;
this.hobbies = hobbies;
this.role = "";
}
// define a setter for role in Person data
Name.prototype.setRole = function(role) {
this.role = role;
}
// define a JSON conversion "method" associated with Person
Name.prototype.toJSON = function() {
const obj = {age: this.age, grade: this.grade, hobbies: this.hobbies, role: this.role};
const json = JSON.stringify(obj); // json/string is useful when passing data on internet
return json;
}
// make a new Person and assign to variable teacher
var SoccerCaptain = new Member("Shree Mehta", "12th", ["Dancing", "Going to the beach", "Painting"]); // object type is easy to work with in JavaScript
logItType(SoccerCaptain); // before role
logItType(SoccerCaptain.toJSON()); // ok to do this even though role is not yet defined
// output of Object and JSON/string associated with Teacher
SoccerCaptain.setRole("Soccer Captain"); // set the role
logItType(SoccerCaptain);
logItType(SoccerCaptain.toJSON());