92 lines
2.6 KiB
HTML
92 lines
2.6 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>TITLE</title>
|
||
|
</head>
|
||
|
<body>
|
||
|
<p id="car"></p>
|
||
|
<p id="car2"></p>
|
||
|
<p id="car_engine"></p>
|
||
|
<p id="car_engine_fuel"></p>
|
||
|
<p id="kiiras"></p>
|
||
|
<p id="carinfo"></p>
|
||
|
<p id="kiir2"></p>
|
||
|
<p id="kiir3"></p>
|
||
|
<p id="kiir4"></p>
|
||
|
<script>
|
||
|
let kiiras = document.getElementById("kiiras");
|
||
|
//objeltum literál
|
||
|
let car = {
|
||
|
// mezők
|
||
|
name : "Fiat",
|
||
|
model : "500",
|
||
|
engine : {
|
||
|
horsepower : 110,
|
||
|
fuel: "benzin",
|
||
|
},
|
||
|
|
||
|
//metódusok
|
||
|
start : function(){
|
||
|
return "Autó elindul!";
|
||
|
},
|
||
|
|
||
|
drive : function(){
|
||
|
return "Autó megy!";
|
||
|
},
|
||
|
|
||
|
kiir : function(){
|
||
|
kiiras.innerHTML = `Név: ${car.name} <br>`;
|
||
|
kiiras.innerHTML += `Megy az autó? ${car.drive()} <br>`;
|
||
|
kiiras.innerHTML += `Mennyi a lóereje: ${car.engine.horsepower} <br>`;
|
||
|
},
|
||
|
|
||
|
carInfo : function(){
|
||
|
return this.name + ", " + this.model;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
let car2 = new Object();
|
||
|
car2.name = "Fiat";
|
||
|
car2.model = "500";
|
||
|
car2.start = function(){
|
||
|
return "Autó elindul!";
|
||
|
};
|
||
|
car2.drive = function(){
|
||
|
return "Autó megy!";
|
||
|
};
|
||
|
|
||
|
document.getElementById("car").innerHTML = car.drive;
|
||
|
document.getElementById("car2").innerHTML = car2.model;
|
||
|
document.getElementById("car_engine").innerHTML = car.engine.horsepower;
|
||
|
|
||
|
//undorítóbb módon való elérés
|
||
|
document.getElementById("car_engine_fuel").innerHTML = car["engine"]["fuel"];
|
||
|
|
||
|
car.kiir();
|
||
|
document.getElementById("carinfo").innerHTML = car.carInfo();
|
||
|
|
||
|
//tömbök
|
||
|
let tomb1 = ["alma", "körte", car, 1, 2.4];
|
||
|
let tomb2 = new Array("alma", "a", car2, 3);
|
||
|
|
||
|
let kiir2 = document.getElementById("kiir2");
|
||
|
tomb1.forEach(element => {
|
||
|
kiir2.innerHTML += element + ", ";
|
||
|
});
|
||
|
|
||
|
tomb2[0] = "szilva";
|
||
|
let kiir3 = document.getElementById("kiir3").innerHTML = tomb2[0] + " " + tomb2[tomb2.length - 1];
|
||
|
|
||
|
|
||
|
let kiir4 = document.getElementById("kiir4");
|
||
|
for (let index = 0; index < tomb2.length; index++) {
|
||
|
const element = tomb2[index];
|
||
|
kiir4.innerHTML += element + " ";
|
||
|
|
||
|
}
|
||
|
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|