Answers for "javascript html class"

89

js set class

var element = document.getElementById('element');
element.classList.add('class-1');
element.classList.add('class-2', 'class-3');
element.classList.remove('class-3');
Posted by: Guest on May-07-2020
74

javascript class

class ClassMates{
	constructor(name,age){
    	this.name=name;
      	this.age=age;
    }
  	displayInfo(){
    	return this.name + "is " + this.age + " years old!";
    }
}

let classmate = new ClassMates("Mike Will",15);
classmate.displayInfo();  // result: Mike Will is 15 years old!
Posted by: Guest on November-20-2019
2

js class

class Car {
  constructor(brand, speed) {
    this.brand = brand
    this.speed = speed
  }
  speedUp() {
    this.speed += 5
    console.log(`The ${this.brand} is travelling at ${this.speed} mph`)
  }
  slowDown() {
    this.speed -= 5
    console.log(`The ${this.brand} is travelling at ${this.speed} mph`)

  }
}
const redCar = new Car('toyota', 0)
redCar.speedUp() // result: The toyota is travelling at 5 mph
redCar.slowDown() // result: The toyota is travelling at 0 mph
Posted by: Guest on April-27-2021
1

class in javascript

class Car {
    constructor(name, year) {
        this.name = name;
        this.year = year;
    }
    age(x) {
        return x - this.year;
    }
}

let date = new Date();
let year = date.getFullYear();

let myCar = new Car("Ford", 2014);
document.getElementById("class1").innerHTML = "My car is " + myCar.age(year) + " years old.";
Posted by: Guest on May-29-2021
1

class javascript

class Polygon {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }

  get area() {
    return this.calcArea();
  }

  calcArea() {
    return this.height * this.width;
  }
}

const square = new Polygon(10, 10);

console.log(square.area);
Posted by: Guest on April-05-2021

Code answers related to "javascript html class"

Code answers related to "Javascript"

Browse Popular Code Answers by Language