我使用OpenWeatherMap API创建了一个简单的天气应用。架构如下:
{
"coord": {
"lon": -122.08,
"lat": 37.39
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"base": "stations",
"main": {
"temp": 282.55,
"feels_like": 281.86,
"temp_min": 280.37,
"temp_max": 284.26,
"pressure": 1023,
"humidity": 100
}...
我正在尝试访问包含数组的天气键内的值。这是我尝试过的:
let iconImage = '';
data.weather.map((description, icon) => {
this.description.textContent += description;
iconImage += icon;
});
this.icon.setAttribute('src', data.weather.icon);
说明和图标是变量,它们指向我的html代码中的li元素,应该在这些元素中输入我从API获得的数据。
我该怎么做才正确?
答案 0 :(得分:1)
const Discord = require('discord.js')
const client = new Discord.Client()
const complements = [
...
]
client.once('ready', () => {
console.log('Logged in!');
client.user.setActivity("with nice complements.")
setInterval(console.log,1000,complements[Math.floor(Math.random() * (complements.length - 1))]);
});