if(e.target.value === 'amd') { // '=' => '==='
ads.textContent = amd
} else if(e.target.value === 'azn') { // '=' => '==='
ads.textContent = azn
} else {
ads.textContent = usd
}
Должно работать так же как и с
const puppeteer = require('puppeteer');
const siteURLs = ['http://example0.com', 'http://example1.com', 'http://example2.com'];
function makeScreenshotFromSite(url, page) {
return page.setViewport({width: 1600, height: 1200})
.then(() => {
return page.goto(siteURL,{ waitUntil: 'networkidle2' });
})
.then(() => {
return page.screenshot({path: '__PNG.png', fullPage: true});
});
};
async function start(sites) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const someRes = await Promise.all(
sites.map(makeScreenshotFromSite)
);
await browser.close();
}
var klick_button = document.getElementById('ras');
klick_button.onclick = function() {
var cel_fun = 0;
var u=[];
var v=[];
var mat=[
[],
[],
];
var rows = document.getElementById("x").value,
columns = document.getElementById("y").value;
for(var i = 0; i < rows; i++){
for(var j = 0; j < columns; j++){
var value_1, value_2;
value_1 = parseInt(document.getElementById('input-' + i + "-" + j).value);
value_2 = parseInt(document.getElementById('input2-' + i + "-" + j).value);
cel_fun = cel_fun + (value_1 * value_2);
n=n+1;
if (value_1 != 0) {
mat[n][0]=u[i];
mat[n][1]=v[j];
mat[n][2]=value_2;
}
}
}
alert(mat[0][2]);
}
const get = timeout => url =>
Promise.race([
fetch(url),
new Promise((resolve, reject) =>
setTimeout(() => reject(new Error('timeout')), timeout)
)
]);
// helpers start
const compose = (fn1, fn2) => x => fn1(fn2(x));
const reduceByProp = prop => a =>
a.reduce((acc, curr) => ({ ...acc, [curr[prop]]: curr }), {});
const uniqByProp = prop => compose(Object.values, reduceByProp(prop));
// helpers end
// logic start
const uniqByLastname = uniqByProp('lastname')
const getUniqAndPrint = compose(console.log, uniqByLastname)
// logic end
// exec start
const arr = [
{
'name': 'anna',
'lastname': 'petrova'
},
{
'name': 'vika',
'lastname': 'ivanova'
},
{
'name': 'julia',
'lastname': 'petrova'
},
];
getUniqAndPrint(arr);
// exec end
При таком коде
.then(res => res.ok ? res.json() : Promise.reject(res.text()))
И еще такой вопрос:
.then(res => res.json())
.then(res => res.users)
почему нельзя сразу возвратить users, вот так?
.then(res => res.json().users)
Body.json()
Takes a Response stream and reads it to completion. It returns a promise that resolves with the result of parsing the body text as JSON, which is a JavaScript value of datatype object, string, etc.
while (true) {
// do something here
}
fetch('http://localhost:3001/register', {
method: 'post',
body: data
})
.then(response => {
if (!response.ok) {
throw new Error('my api returned an error')
}
return response.json()
})
.then(user => {
console.log(user)
})
await httpGet("/article/promise/user.json").then(...)
console.log('не лезь');
/**
* какая-то функция, которая возвращает поле объекта name
* @returns {String}
*/
function getName () {
return this.name ? this.name : null;
}
var obj1 = {
name: 'name1',
getName: getName
}
var obj2 = {
name: 'name2',
getName: getName
}
// в данном случае, getName смотрит на obj1#name
console.log(obj1.getName()) // name1
// в данном случае, getName смотрит на obj2#name
console.log(obj2.getName()) // name2