Console Log Output

console.log("Hello, World!");
Hello, World!
var msg = "Hello, World!";
console.log(msg);
Hello, World!
function logIt(output) {
    console.log(output);
}
logIt(msg);
Hello, World!
console.log("Reuse!")
logIt("Hello, Students!");
logIt(2022)
Reuse!
Hello, Students!
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]);
Looking at dynamic nature of types in JavaScript
string ; Hi Class!
number ; 2022
object ; [ 1, 2, 3 ]

Building a Person Function/Class object

// 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());
object ; Person { name: 'Mr M', ghID: 'jm1021', classOf: 1977, role: '' }
string ; {"name":"Mr M","ghID":"jm1021","classOf":1977,"role":""}
object ; Person { name: 'Mr M', ghID: 'jm1021', classOf: 1977, role: 'Teacher' }
string ; {"name":"Mr M","ghID":"jm1021","classOf":1977,"role":"Teacher"}

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());
object ; Member {
  name: 'Shree Mehta',
  grade: '12th',
  events: [ 'Dancing', 'Going to the beach', 'Painting' ],
  role: '' }
string ; {"name":"Shree Mehta","grade":"12th","events":["Dancing","Going to the beach","Painting"],"role":""}
object ; Member {
  name: 'Shree Mehta',
  grade: '12th',
  events: [ 'Dancing', 'Going to the beach', 'Painting' ],
  role: 'Soccer Captain' }
string ; {"name":"Shree Mehta","grade":"12th","events":["Dancing","Going to the beach","Painting"],"role":"Soccer Captain"}