const itemsContainer = document.getElementById('shop-items-container') // container ı seç
let d;
products.forEach(function(x, i){
if (i % 2 == 0){ // burada arrayin index numarası çift sayı ise | 0, 2, 4, 6 gibi yeni bir div oluşturup class olarakta 'shop-line' atıyoruz
d = document.createElement('div')
d.classList.add('shop-line')
}
// innerHTML ile veriyi oluşturulan div e ekliyoruz
d.innerHTML += `<div class="shop-item">
<img class="item-image" src="${x.image}">
<div class="top-class">
<p class="item-name">${x.name}</p>
<p class="item-price">${x.price}</p>
</div>
<p class="item-description">${x.description}</p>
</div>`;
if (i % 2 != 0 || i == products.length - 1){ // index numarası tek ise veya arrayin son elemanıysa container içerisine oluşturulan divi ekliyoruz.
itemsContainer.appendChild(d)
}
})
doğru çalışıyor gibi umarım işini görür.
Hafta içi her gün mesai saatlerine göre hesaplıyor.
function calculate($from, $to)
{
$workingDays = [1, 2, 3, 4, 5];
$from = new DateTime($from);
$interval = new DateInterval("PT1S");
$r = ($to * 10) + 172800;
$periods = new DatePeriod($from, $interval, $r);
$sec = 0;
foreach ($periods as $period) {
if (!in_array($period->format('N'), $workingDays)) continue;
$h = intval($period->format('H'));
$m = intval($period->format('i'));
if($sec >= $to){
return $period->format('Y-m-d H:i:s');
break;
}
// 07:15 09:00 09:15 12:00 12:45 15:15 15:30 17:00
if(($h >= 7 && $m >= 15) && ($h <= 8 && $m <= 59) || ($h >= 9 && $m >= 15) && ($h <= 11 && $m <= 59) || ($h >= 12 && $m >= 45) && ($h <= 15 && $m <= 14) || ($h >= 15 && $m >= 30) && ($h <= 16 && $m <= 59)){
$sec++;
}
}
}
echo calculate("2021-12-01 07:15:00", 13000); // 2021-12-01 11:51:40
indexOf u yanlış kullanmışsın.
let i = school.indexOf("Anadolu")
console.log(i) // kelime bulunamadıysa değer -1 döner.Bulunduysa kelimenin başladığı index numarası döner.
if (i != -1){
okulAdi.classList.add('green')
}else if(i == -1) {
okulAdi.classList.remove('green')
okulAdi.classList.add('red')
}
Eğer masaüstü uygulaması yapmak istiyorsan en basit yöntem .NET Core ile Windows Forms uygulaması yapabilirsin.
Veritabanı yerine .xml dosyasına kaydedersin verileri gerektiğinde de okuyup program içerisinde kullanabilirsin.
// onmessage içerisinde
const lastPrice = data.c
const openPrice = data.o
price.innerHTML = (lastPrice - openPrice) / openPrice + '%'
bu şekilde yapabilirsin ama zaten bunu data.P ile çekebiliyorsun sanırım aynı değeri veriyor.
aşağıdaki linkte gelen verinin açıklamalarını görebilirsin.
https://github.com/binance/binance-spot-api-docs/blob/master/web-socket-streams.md#individual-symbol-ticker-streams
anlık olarak almak istiyorsan websocket ile yapmalısın.
<div id="price"></div>
const ws = new WebSocket('wss://stream.binance.com:9443/ws/btcusdt@ticker')
const price = document.getElementById('price') // veriyi yazdıracağımız html elementini seçiyoruz
ws.onmessage = (e) => {
const data = JSON.parse(e.data)
price.innerHTML = data.p // seçilen elemente istediğimiz veriyi yazdırıyoruz
console.log(data)
}
şöyle birşey mi yapmak istiyorsun?
<input id="color" type="color"/>
const color = document.getElementById('color')
color.addEventListener('input', function(){
document.body.style.backgroundColor = this.value
})
https://youtu.be/8Pd6wHn-xfw
https://github.com/luukdv/color.js
color.js ile resimden renk alabilirsin.
<table class="table">
<tr id="txt">
</tr>
</table>
const txt = document.getElementById('txt')
const xhr = new XMLHttpRequest();
xhr.addEventListener('load', function(){
const data = JSON.parse(this.responseText)
for(var k in data){
const td = document.createElement('td')
td.innerText = data[k]
td.classList.add(k)
txt.appendChild(td)
}
})
xhr.open('GET', 'https://api.binance.com/api/v1/ticker/24hr?symbol=BTCUSDT')
xhr.send()