我正在運行cron,每30秒檢查一次價格,并將資產的價值回傳給我。
如果價格與之前的價格不同,我想把它記錄下來。我正在測驗這個,因為這對我未來的想法非常有用...... price變數保存著價格。我的目標是在變數不同時做一些動作。
//Stuff above the code like cron and general discord client.on ↑
//這將記錄資產的當前價格。
console.log(price, 'PRICE UPDATED! ')
//試圖比較價格,但這是不成功的,因為它沒有做任何事情...。
var Previousprice = null;
function foo() {
var Currentprice = $(price.toFixed(2)
if (Previousprice == Currentprice) {
$(price.toFixed(2)
console.log('Price is same! ')
}
Previousprice=Currentprice
console.log('Price has changed!'/span>)
//new discord action...。
}
});
});
});
});
到目前為止,我也試過這樣做,但我認為這完全是無用的,不會有這樣的效果......
。
console.log(price, 'price UPDATED!')
let Previousprice = null;
let Currentprice = price
if (price) {
let Previousprice = price.toFixed(2)
console.log(price, 'Price defined')
} else if(Previousprice == Currentprice) {
console.log(price, 'Price is same'/span>)
} else if(Previousprice !== Currentprice) {
let Previousprice = price.toFixed(2)
console.log(price, 'Price changed! ')
Logs。
1.29739982471208 PRICE UPDATED!
1.29739982471208 Price 定義
1.29739982471208 PRICE UPDATED!
1.29739982471208 Price 定義
1.29660532105896 PRICE UPDATED!
1.29660532105896 Price 定義的
uj5u.com熱心網友回復:
你每隔30秒就重新宣告并分配previousPrice = null; 。在沒有看到周圍代碼的情況下,我不能給你具體的資訊,但你通常想要的是一個全域變數,如currentPrice,在應用程式第一次運行時初始化為0。
//初始化一個初始值為0的全域變數。
let currentPrice = 0;
// Stuff above the code like cron and general discord client.on
console.log(price, 'PRICE UPDATED!') 。
if (price !== currentPrice) {
console.log(`Price changed from ${currentPrice} to ${price}`)。
currentPrice = price。
}
else {
console.log(`Price remains at ${currentPrice}`) 。
}
第一次運行顯然會將價格從0變為第一個初始價格,但這很好。
uj5u.com熱心網友回復:
好的,那么你有沒有嘗試過previous_price = current_price,在將previous_price設定為當前的某個價格之后,運行它,然后在console.log之后,如果它是不同的或者其他的,那么它就會被設定為當前的價格,然后在每個內部之后都會改變?
這樣做應該可以。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/316177.html
標籤:
上一篇:如何將WCF服務發布到IIS?
