Promises - unable to execute the following code...it is showing error: endsWith() is not a function

error: endsWith() is not a function.this is my code:
function download(val){
return new Promise(function(resolve,reject){

if(val.startsWith(“http”))
{
console.log(“downloaded”)
resolve(val);
}
else{
reject(“not”);
}
})
}
function resize(val){
return new Promise(function(resolve,reject){
if(val.endsWith(".png"))
{
resolve(“resize”);
}
else{
reject(“not2”);
}
})
}
Promise.all([download(“http:njxnkn.png”),download(“http-cx.png”)]).then(resize).then(function(val){
return Promise.all(val.map(resize))
}).then(function(values){
console.log(values);
}).catch(function(val){
console.log(val);
})

Here remove .then(resize)

1 Like

unable to run the code .it is showing
throw err;
^ [Error: EPERM: operation not permitted, write] { errno: -4048, code: ‘EPERM’, syscall: ‘write’ }

code:
const fs=require(‘fs’)
fs.writeFile(‘myfile.txt’," mouse",function(err){
if(err){
throw err;
}
console.log(“file was written”);

})

What is the location of your file myfile.txt?

js file and myfile.txt are in the same folder

$(()=>{

$(’#btn’).click(()=>{
let text=$(’#in’).val()
$(’#list’).prepend($(’

  • ${text}
  • ’))
    })

    })
    it is adding ‘${text)’ to the list instead of text value (there’s li attr enclosing ${text})

    Please make separate issues for each doubt. Its very difficult to track multiple doubts on a single thread.
    Also, use the code insert button while inserting code in doubt panel, the jQuery code you just posted in missing some content. Pls make a new issue with proper code insertions.

    Regarding the jQuery code, lines are missing in the text you pasted, so I am not able to resolve it.