12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- // function confirmPromise(text){
-
- // return new Promise((fulfill, reject) => {
- // let a = confirm(text);
- // if(a === false){
- // reject("i'm absent")
- // }else{
- // fulfill("yes")
- // }
- // })
- // }
- // confirmPromise("Are you here?")
- // .then((result)=>{console.log(result);})
- // .catch((result)=>console.log(result))
- function promptPromise(text){
-
- return new Promise((fulfill, reject) => {
- let a = prompt(text);
- if(a === null || a === ""){
- reject("i'm absent")
- }else{
- fulfill(a)
- }
- })
- }
- promptPromise("What is your name?")
- .then((res)=>console.log(res))
- .catch((res)=>console.log(res))
- // let {login,password} = await loginFormPromis()
- const login = document.getElementById("login");
- const password = document.getElementById("password");
- const btnCancel = document.getElementById("cancel");
- const btnCheck = document.getElementById("check");
- const result = document.getElementById("result");
- function loginForm(e){
- const p = new Promise((fulfill,reject)=>{
- let log = login.value;
- let pass = password.value;
- const user = {
- login:"",
- password: "",
- }
- if((log !== "" && log !== undefined)&&(pass !== "" && pass !== undefined && e.target !== btnCancel)){
- user.login = log;
- user.password = pass;
- fulfill(user);
- }else{
- reject("something is wrong");
- }
- })
- p.then((user) => console.log(user))
- .catch((res)=>{
- login.value = "";
- password.value = "";
- console.log(res)
- });
-
- }
- btnCheck.addEventListener("click", loginForm)
- btnCancel.addEventListener("qclick", loginForm)
|