0

I'm kinda new here. Started speedrun ethereum.

I finished the code for quest 2, but timeleft() is not displaying at the front end. It just shows "0" everytime, even redeploying and changing the deadline time.

If i can make this question better, please tell me. Also english is not my first language.

Code snippets:

function timeLeft() public view returns(uint256){
        if (block.timestamp >= deadline){
            return 0;
        } else{
            uint timeleft = block.timestamp - deadline;
            return timeleft;
        }
<p className="m-0 p-0">{timeLeft ? `${humanizeDuration(Number(timeLeft) * 1000)}` : 0}</p>
inputs: [],
          name: "timeLeft",
          outputs: [
            {
              internalType: "uint256",
              name: "",
              type: "uint256",
            },
          ],
          stateMutability: "view",
          type: "function",
        },

1 Answer 1

0

I think you inverted the sign:

// uint timeleft = block.timestamp - deadline;  wrong
uint timeleft = deadline - block.timestamp;  // correct
1
  • 1
    Yes, it was that. Thanks for answering my question!
    – Patok
    Commented Mar 5 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.