0

I am stuck at Step-6 of Bitdegree's Solidity tutorial. Question is to Emit an event ScoreChanged with two arguments: int amount (equal to the value that was sent) and bool direction (true for up function and false for down).

This is my solution for this,I have previously checked it with remix and there are no errors in my code. I am able to pass second test case where I have to write bool direction event but stuck at int amount event.I am not able to figure out why my solution is not getting accepted? I hope someone can help me. I am beginner in Solidity.

pragma solidity 0.4.17;
contract TugOfWar {

    int public score = 0;
    int constant endAt = 1 ether;
    bool public gameOver = false;
    bool public _direction;
    /*I even tried this
    event ScoreChanged(int indexed _amount, bool indexed _direction);*/
    event ScoreChanged(int _amount, bool _direction);
    event GameEnded(bool _gameOver);

    function up() external payable {
        require(msg.value > 0);
        require(!gameOver);

        int value = int(msg.value);
        score += value;

         ScoreChanged(value,true);

        checkIfGameOver();
    }

    function down() external payable {
        require(msg.value > 0);
        require(!gameOver);

        int value = int(msg.value);
        score -= value;

         ScoreChanged(value,false);

        checkIfGameOver();
    }

    function checkIfGameOver() internal {
        if(score >= endAt || score <= endAt * -1) {
            gameOver = true;
             GameEnded(gameOver);
        }
    }
}
  • What's the problem / what's your question? – smarx Mar 27 '18 at 2:45
  • I am not able to figure out why my solution is not getting accepted? – Ayush Sharma Mar 27 '18 at 2:48
  • Is there a test case you have to pass? Do you know what that test is doing? Your code definitely emits an event. – smarx Mar 27 '18 at 2:50
  • Perhaps if you shared the text of what you're supposed to do, somebody might be able to spot the issue. – smarx Mar 27 '18 at 2:51
  • No there is no as such test case which I need to pass. These is the exact text what is written over there: 'Emit an event ScoreChanged with two arguments: int amount (equal to the value that was sent) and bool direction (true for up function and false for down)' – Ayush Sharma Mar 27 '18 at 2:57
0

I just zipped through to lesson six. The second task is:

Emit an event ScoreChanged with two arguments: int amount (equal to the value that was sent) and bool direction (true for up function and false for down)

Your parameters are incorrectly named. Rename them to match:

event ScoreChanged(int amount, bool direction);
  • I am able to pass the second task with my code. The problem lies in the 1st task. I hope you can help me out. – Ayush Sharma Mar 27 '18 at 3:01
  • Your existing code looks correct for the first task. – smarx Mar 27 '18 at 3:02
  • Oh, sorry, your parameters are incorrectly named. – smarx Mar 27 '18 at 3:02
  • Yep, there is no error but I am not able to pass it and according to their policy, I can't proceed to next chapter until I have successfully submitted previous programming exercises. – Ayush Sharma Mar 27 '18 at 3:03
  • OMG !! Changing parameters' name helped but one can name them anything, correct? – Ayush Sharma Mar 27 '18 at 3:06
0

here is the correct code.

pragma solidity ^0.4.17;

contract TugOfWar {

    int public score = 0;
    int constant endAt = 1 ether;
    bool public gameOver = false;
    event GameEnded(bool gameOver);
    event ScoreChanged(int amount,bool direction);

    function up() external payable {
        require(msg.value > 0);
        require(!gameOver);

        int value = int(msg.value);
        int amount= value;
        bool direction=true;
        score += value;

        //
        emit ScoreChanged(amount,direction);

        checkIfGameOver();
    }

    function down() external payable {
        require(msg.value > 0);
        require(!gameOver);

        int value = int(msg.value);
        int amount=value;
        bool direction=false;
        score -= value;

        //
        emit ScoreChanged(amount,direction);

        checkIfGameOver();
    }

    function checkIfGameOver() internal {
        if(score >= endAt || score <= endAt * -1) {
            gameOver = true;

            //
            emit GameEnded(gameOver);
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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