I think I’m missing something here…I built a script for daily weather forecast from Dark Sky.
This set of code from the main body of script works fine:
let place = await Location.current()
let keys = devKey()
let site = “https://api.darksky.net/forecast/”
let url = site + keys + “/” + place.latitude + “,” + place.longitude
let req = new Request(url)
let json = await req.loadJSON()
For sake of better modularity and more importantly for some simple mocking of the API call, I tried to move this to a function, like below, but get a syntax error. Any ideas on what might be wrong?
SyntaxError: Unexpected identifier ‘req’. Expected ‘;’ after variable declaration
let place = await Location.current()
let json = getWeather(place)
function getWeather(place) {
let keys = devKey()
let site = “https://api/darksy.net/forecast/”
let url = site + keys + “/” + place.latitude + “,” + place.longitude
let req = new Request(url)
let json = await req.loadJSON()
return json
}