Function Solidity setName函数编程(位度)

Function Solidity setName函数编程(位度),function,blockchain,ethereum,solidity,Function,Blockchain,Ethereum,Solidity,作为Bitdegree学习巩固课程的一部分。我被要求做以下工作: 以允许设置name值的方式修改函数setName 2.创建一个名为increaseCounter的新函数,该函数将在每次调用时将计数器的值增加10 我尝试过多种设置名称的方法,但是遇到了很多问题,如果有人能帮我解决这个问题,我将不胜感激,它非常基本,但由于某些原因,没有任何效果:(.这是当前的代码。) pragma solidity ^0.4.16; contract FunctionTest { bool public foo

作为Bitdegree学习巩固课程的一部分。我被要求做以下工作:

  • 以允许设置name值的方式修改函数setName
  • 2.创建一个名为increaseCounter的新函数,该函数将在每次调用时将计数器的值增加10

    我尝试过多种设置名称的方法,但是遇到了很多问题,如果有人能帮我解决这个问题,我将不胜感激,它非常基本,但由于某些原因,没有任何效果:(.这是当前的代码。)

    pragma solidity ^0.4.16;
    
    contract FunctionTest {
    bool public foo = true;
    string public name;
    uint256 public counter = 0;
    
    function setName() public {
        //
    }
    
    function writeToStorage() {
        foo = !foo;
    }
    
    function readFromStorageConstant() public constant returns (bool) {
        return foo;
    }
    
    function readFromStorageView() public view returns (bool) {
        return foo;
    }
    

    }应该非常简单

    pragma solidity ^0.4.16;
    
    contract FunctionTest {
      bool public foo = true;
      string public name;
      uint256 public counter = 0;
    
      function setName(string _name) public {
        name = _name;
      }
    
      function increaseCounter() public {
        counter += 10;
      }
    
      function writeToStorage() {
        foo = !foo;
      }
    
      function readFromStorageConstant() public constant returns (bool) {
        return foo;
      }
    
      function readFromStorageView() public view returns (bool) {
        return foo;
      }
    }
    

    应该很简单

    pragma solidity ^0.4.16;
    
    contract FunctionTest {
      bool public foo = true;
      string public name;
      uint256 public counter = 0;
    
      function setName(string _name) public {
        name = _name;
      }
    
      function increaseCounter() public {
        counter += 10;
      }
    
      function writeToStorage() {
        foo = !foo;
      }
    
      function readFromStorageConstant() public constant returns (bool) {
        return foo;
      }
    
      function readFromStorageView() public view returns (bool) {
        return foo;
      }
    }
    

    出于某种原因,它需要将变量“name”初始化为字符串才能提交

    pragma solidity ^0.4.16;
    
    contract FunctionTest {
      bool public foo = true;
      string public name="ChuckNorris";
      uint256 public counter = 0;
    
      function setName(string _name) public {
        name = _name;
      }
    
      function increaseCounter() public {
        counter += 10;
      }
    
      function writeToStorage() {
        foo = !foo;
      }
    
      function readFromStorageConstant() public constant returns (bool) {
        return foo;
      }
    
      function readFromStorageView() public view returns (bool) {
        return foo;
      }
    }
    

    出于某种原因,它需要将变量“name”初始化为字符串才能提交

    pragma solidity ^0.4.16;
    
    contract FunctionTest {
      bool public foo = true;
      string public name="ChuckNorris";
      uint256 public counter = 0;
    
      function setName(string _name) public {
        name = _name;
      }
    
      function increaseCounter() public {
        counter += 10;
      }
    
      function writeToStorage() {
        foo = !foo;
      }
    
      function readFromStorageConstant() public constant returns (bool) {
        return foo;
      }
    
      function readFromStorageView() public view returns (bool) {
        return foo;
      }
    }
    

    请确保您回答了问题的两个部分。由于某些原因,在完成increaseCounter()函数之前,本课中的setName()函数不会显示您已正确完成。以下是帮助我提升到下一个级别的解决方案

    pragma solidity ^0.4.16;
    
    contract FunctionTest {
      bool public foo = true;
      string public name;
      uint256 public counter = 0;
    
      function setName(string _name) public {
        name = _name;
      }
    
      function increaseCounter() public {
        counter += 10;
      }
    
      function writeToStorage() {
        foo = !foo;
      }
    
      function readFromStorageConstant() public constant returns (bool) {
        return foo;
      }
    
      function readFromStorageView() public view returns (bool) {
        return foo;
      }
    
      funciton increaseCounter() {
        counter += 10; } 
    }
    

    请确保您回答了问题的两个部分。由于某些原因,在完成increaseCounter()函数之前,本课中的setName()函数不会显示您已正确完成。以下是帮助我提升到下一个级别的解决方案

    pragma solidity ^0.4.16;
    
    contract FunctionTest {
      bool public foo = true;
      string public name;
      uint256 public counter = 0;
    
      function setName(string _name) public {
        name = _name;
      }
    
      function increaseCounter() public {
        counter += 10;
      }
    
      function writeToStorage() {
        foo = !foo;
      }
    
      function readFromStorageConstant() public constant returns (bool) {
        return foo;
      }
    
      function readFromStorageView() public view returns (bool) {
        return foo;
      }
    
      funciton increaseCounter() {
        counter += 10; } 
    }
    

    谢谢,我最初在运行它从未编译过的代码时尝试过这一点。如果我在其他浏览器上尝试/刷新它,可能会起作用。我仍然没有部署代码。啊,啊,啊,啊,那就不是编码问题。你必须用你的环境和你正在采取的步骤的信息更新你的帖子。出于某种原因,这是错误的我接受了将字符串public name分配给函数外的某个名称的请求,并接受了该请求。仍然不确定为什么以前没有在平台上部署它,但感谢您的帮助!谢谢,我最初在运行它从未编译过的代码时尝试了此操作。如果我在其他浏览器上尝试/刷新它,可能会奏效。谢谢我不会部署CODEE ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh但是谢谢你的帮助!