script.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // function confirmPromise(text){
  2. // return new Promise((fulfill, reject) => {
  3. // let a = confirm(text);
  4. // if(a === false){
  5. // reject("i'm absent")
  6. // }else{
  7. // fulfill("yes")
  8. // }
  9. // })
  10. // }
  11. // confirmPromise("Are you here?")
  12. // .then((result)=>{console.log(result);})
  13. // .catch((result)=>console.log(result))
  14. function promptPromise(text){
  15. return new Promise((fulfill, reject) => {
  16. let a = prompt(text);
  17. if(a === null || a === ""){
  18. reject("i'm absent")
  19. }else{
  20. fulfill(a)
  21. }
  22. })
  23. }
  24. promptPromise("What is your name?")
  25. .then((res)=>console.log(res))
  26. .catch((res)=>console.log(res))
  27. // let {login,password} = await loginFormPromis()
  28. const login = document.getElementById("login");
  29. const password = document.getElementById("password");
  30. const btnCancel = document.getElementById("cancel");
  31. const btnCheck = document.getElementById("check");
  32. const result = document.getElementById("result");
  33. function loginForm(e){
  34. const p = new Promise((fulfill,reject)=>{
  35. let log = login.value;
  36. let pass = password.value;
  37. const user = {
  38. login:"",
  39. password: "",
  40. }
  41. if((log !== "" && log !== undefined)&&(pass !== "" && pass !== undefined && e.target !== btnCancel)){
  42. user.login = log;
  43. user.password = pass;
  44. fulfill(user);
  45. }else{
  46. reject("something is wrong");
  47. }
  48. })
  49. p.then((user) => console.log(user))
  50. .catch((res)=>{
  51. login.value = "";
  52. password.value = "";
  53. console.log(res)
  54. });
  55. }
  56. btnCheck.addEventListener("click", loginForm)
  57. btnCancel.addEventListener("qclick", loginForm)