0

I am getting the below error when i compile the below code. Using remix compiler version 0.5.11

****browser/TodoList.sol:7:2: ParserError: Expected pragma, import directive or contract/interface/library definition.
 struct Task {
 ^----^****
pragma solidity >=0.5.0 <0.6.0 ;

contract TodoList {
    uint public taskCount = 0;
}

 struct Task {
    uint id;
    string content;
    bool completed;
}

mapping(uint => Task) public tasks;

event TaskCreated(uint id,string content,bool completed);
event TaskToggled(uint id,bool completed);

construct() public {
    createTask("Default Todo Task");
}

function createTask(string memory _content) public{
    taskCount ++;
    tasks[taskCount]=Task(taskCount, _content, false);
    emit TaskCreated(taskCount, _content, false);
}

function toggleTask(uint _id) public {
    Task memory _task = tasks[_id];
    _task.completed = !_task.completed;
    tasks[_id] = _task;
    emit TaskToggled(_id, _task.completed);
}
  • 1
    Move the closing curly brace of the contract to the bottom of the file! – goodvibration Jul 12 at 8:16
0

Use remix to debug your code. Here's the corrected code.

pragma solidity >=0.5.0 <0.6.0 ;

contract TodoList {
    uint public taskCount = 0;


 struct Task {
    uint id;
    string content;
    bool completed;
}

mapping(uint => Task) public tasks;

event TaskCreated(uint id,string content,bool completed);
event TaskToggled(uint id,bool completed);

constructor() public { //spelling of constructor was wrong. Here it is corrected.
    createTask("Default Todo Task");
}

function createTask(string memory _content) public{
    taskCount ++;
    tasks[taskCount]=Task(taskCount, _content, false);
    emit TaskCreated(taskCount, _content, false);
}

function toggleTask(uint _id) public {
    Task memory _task = tasks[_id];
    _task.completed = !_task.completed;
    tasks[_id] = _task;
    emit TaskToggled(_id, _task.completed);
}

}//moved the curly bracket to the end of the code from above

You've made 2 mistakes. I've commented the errors. Cheers

| improve this answer | |

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.