var text = document.getElementById('text');
text.title = "New text";
console.log(text.title);
text.style.color = "red";
text.style.backgroundColor = "blue";
text.innerHTML = "New<br>style";🔥2
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
info () {
console.log("Имя: " + this.name + ", Возраст: " + this.age);
}
}
var bob = new Person('Bob', 23);
var alex = new Person('Alex', 45);
alex.name = "Sergey"
bob.name = "Ivan"
alex.info()
bob.info()
//console.log(alex.name + " " + alex.age);
//console.log(bob.name + " " + bob.age)❤3
const SumNumbers = (a, b) => {
if (typeof a !== 'number' || typeof b !== 'number') {
return "a and b не числа!"
}
if (a <= 0 || b <= 0) {
return "Неприемливые числа"
}
return a + b
}
let sum = SumNumbers(55, 5)
console.log(sum)❤1🔥1
Forwarded from КосмоНавт (KosmoNavt.cpp)
Please open Telegram to view this post
VIEW IN TELEGRAM
🥰2❤1
const myObject = {
x: 12,
y: true,
z: 'hi'
}
Object.values(myObject).forEach(values => {
console.log(values)
})const myObject = {
x: 12,
y: true,
z: 'hi'
}
Object.keys(myObject).forEach(keys => {
console.log(keys)
})Методы keys и values для объектов
🔥2🤔1
Начал изучать классы и прототипы
class Comment {
constructor(text) {
this.text = text
this.votesQty = 0
}
upvote() {
this.votesQty += 1
}
}
const firstComment = new Comment('First comment')❤1👍1🔥1🥰1
https://doka.guide/js/array-reduce/
Чувствую, что с этим я ебаться буду долго...
Дока
.reduce() — JavaScript — Дока
Швейцарский нож для работы с массивами. Заменяет все остальные методы (не повторяйте дома).
😭2
fetch('https://jsonplaceholder.typicode.com/posts')
.then((response) => response.json())
.then((json) => console.log(json));const timerPromise = () =>
new Promise((resolve, reject) =>
setTimeout(() => resolve(), 2000))
const asyncFn = async () => {
console.log('Timer starts')
const startTime = performance.now()
await timerPromise()
const endTime = performance.now()
console.log('Timer ended', endTime - startTime)
}
asyncFn()