1
I’m trying to make a page about data from covid-19! I’m trying to get the total number of dead from two different days using the following code:
var ontem = $.getJSON('https://covid19-brazil-api.now.sh/api/report/v1/brazil/2020' + mes.val() + '0' + diaAnt(), {"deaths": ""}).success(function(data) {
var totais = data.data.reduce((a, b) => a + b.deaths, 0);
return totais;
})
var hoje = $.getJSON('https://covid19-brazil-api.now.sh/api/report/v1/brazil/2020' + mes.val() + dia.val(), function(data) {
var totais = data.data.reduce((a, b) => a + b.deaths, 0)
});
The problem is that it always returns me the following data:
Object { readyState: 1, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, … }
I’ve tried everything but I can’t get the exact amount. Can anyone help?
Edit.: What I want to do is subtract the value of the variable "today" with the variable "yesterday"
I used the code: var sub = $.when(yesterday, today). done(Function(totals, info){ total Return - info; }) console.log(sub); but still it returns to me Object { state: >, Always: ṃ, then: ?, Promise: ?, pipe: ?, ... }
– Pedro Matias de Souza
@Pedromatiasdesouza
var sub
will not solve your problem,return totais - info
does not modifysub
, everything needs to be done within the function defined indone
.– Alex Parloti