#25 李雷向韩梅梅求婚


  • 0

    0_1516695744194_WX20180123-162146.png

    这么严格 : )


  • 1

    var isOK_flag=false;
    alert("MEI,i love you,marry me!!");
    function proposeToMissHan(isOK){
    return new Promise(function (resolve,reject) {
    var time=parseInt(Math.random()*(50-20+1)+20);
    setTimeout(function () {
    isOK ?resolve("ok,yes I DO!"):reject("no, I'M sorry!We are not suitable!")
    },time)
    })
    }
    proposeToMissHan(isOK_flag).then(function (res) {
    alert(res);
    }).catch(function (res) {
    alert(res)
    })


  • 0

    const proposeToMissHan = (isOK) => {
     return new Promise((resolve, reject) => setTimeout(isOK => isOK ? resolve('ok') : reject('no'), Math.floor(Math.random()*31)+20));
    }

  • 0

    const proposeToMissHan = (isOK) => {
    /* TODO */
    var time = Math.floor(50-Math.random()*30)
    return new Promise((resolve,reject)=>{
    setTimeout((resolve)=>{
    if(isOK){
    resolve('ok')
    }else{
    reject('no')
    }
    },time)
    })
    }


  • 0

    @ackerMan return new Promise((resolve, reject) => {
    setTimeout(() => {isOK ? resolve('ok') : reject('no')},20)
    })


  • 0

    const proposeToMissHan = (isOk) => {
    const time = parseInt(Math.random()*(31)+20,10)

    return new Promise( (resolve,reject) => {
           setTimeout( () => {
               isOk ? resolve('ok') : reject('no');
           },time)
    });
    

    }


  • 0

    const proposeToMissHan = (isOK) => {
    return new Promise((resolve,reject)=>{
    setTimeout(isOk => isOk ? resolve('ok') : reject('no'),20);
    })
    }


  • 0

    const proposeToMissHan = (isOK) => {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          isOK ? resolve('ok') : reject('no')
        }, 20)
      })
    }
    

  • 0

    受到 @Superlee 大佬的启发,删掉了then部分,测试通过
    ···
    const proposeToMissHan = (isOK) => {
    let time = Math.random()*31 + 20
    return new Promise((res, rej) => {
    setTimeout(() => isOK ? res('ok') : rej('no'), time)
    })
    }
    ···


  • 0

    const proposeToMissHan = (isOK) => {
        /* TODO */
        const promise = new Promise((resolve, reject) => {
            setTimeout(() => {
                if (isOK) {
                    resolve('ok')
                } else {
                    reject('no')
                }
            }, Math.random() * 30 + 20)
        });
        return promise
    }
    proposeToMissHan(false).then(data => {
        console.log(data)
    }, reason => {
        console.log(reason)
    })
    

登录后回复
 

与 ScriptOJ 的连接断开,我们正在尝试重连,请耐心等待