Skip to content

Commit

Permalink
Update BitcoinPrice.js - optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
chelming authored Oct 30, 2024
1 parent 3882416 commit 05a4284
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Parsers/BitcoinPrice.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ quote.setHttpMethod('GET');
var chatResponse = quote.execute();
var chatResponseBody = JSON.parse(chatResponse.getBody());

if (chatResponseBody && chatResponseBody.bpi && chatResponseBody.bpi.USD && chatResponseBody.bpi.USD.rate) {
if (chatResponseBody?.bpi?.USD?.rate) {
var bitcoinpriceFormatted = chatResponseBody.bpi.USD.rate;
new x_snc_slackerbot.Slacker().send_chat(current, 'The current price of one bitcoin is: ' + bitcoinpriceFormatted + '$', false);
new x_snc_slackerbot.Slacker().send_chat(current, 'The current price of one bitcoin is: $' + bitcoinpriceFormatted + ' USD', false);
}

0 comments on commit 05a4284

Please sign in to comment.