“Hitung Usia dari Tanggal Kelahiran JavaScript” Kode Jawaban

JavaScript mendapatkan usia

function getAge(dateString) 
{
    var today = new Date();
    var birthDate = new Date(dateString);
    var age = today.getFullYear() - birthDate.getFullYear();
    var m = today.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) 
    {
        age--;
    }
    return age;
}
DigitalBorder

JavaScript Kerja Usia Sejak Tanggal Lahir

// To calculate age:
var year_born = prompt("Please enter your date of birth:", "Type here");
var d = new Date();
var n = d.getFullYear();
function getAge(birthYear){
	var currentDate = new Date();
    var currentYear = currentDate.getFullYear();
    age = currentYear - birthYear;
    return age;
}
calculatedAge = getAge(year_born);
alert("Hello, " + "you are " + calculatedAge + " years old!");
Hello There

Hitung Usia dari Tanggal Kelahiran JavaScript

let car = function  (name,model,color){
    this.name = name;
    this.model = model;
    this.color = color;
  //  console.log(model);
    
}
let car1 = new car ("beast", "2022","darkBlue");
let car2 = new car ("sienta", "2001","darkBlue");
let car3 = new car ("wish", "2011","darkBlue");
let car4 = new car ("bmw", "2010","darkBlue");

 console.log(car1);
Nicholas Edgar Kiwanuka

Hitung Usia dari Tanggal Kelahiran JavaScript

let car = function  (name,model,color){
    this.name = name;
    this.model = model;
    this.color = color;
  //  console.log(model);
    
}
let car1 = new car ("beast", "2022","darkBlue");
let car2 = new car ("sienta", "2001","darkBlue");
let car3 = new car ("wish", "2011","darkBlue");
let car4 = new car ("bmw", "2010","darkBlue");

 console.log(car1);
Nicholas Edgar Kiwanuka

Jawaban yang mirip dengan “Hitung Usia dari Tanggal Kelahiran JavaScript”

Pertanyaan yang mirip dengan “Hitung Usia dari Tanggal Kelahiran JavaScript”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya