我想创建两个提示,允许用户将数据添加到模拟API。
到目前为止,这是我的代码。我在将代码嵌入两个提示时遇到麻烦:
let nameOfCity = prompt('City name')
let population = prompt('Population')
fetch('https://notarealapi.com/cities', {
body: '{ "name": "Stockholm", "population": 123 }',
headers: {
'Content-Type': 'application/json'
},
method: 'POST'
})
.then(response => response.json())
.then(result => {
console.log(result)
})
对于第一个提示,我希望能够将城市的名称添加到API中,对于下一个提示,我想要在第一个提示中添加城市的人口。我很困。