자바스크립트 is not defined 오류

자바스크립트 is not defined 오류

작성일 2024.05.18댓글 1건
    게시물 수정 , 삭제는 로그인 필요

영상 강의를 보며 dapp 투표 프로그램을 따라 만드는 중인데요, 여기 25-37번째 줄의 accounts[0]에 access 하고자 하는데 왜 accounts가 정의되지 않았다고 오류 메시지가 뜨는지 잘 모르겠습니다. 위의 candidate같은 경우는 candidate[0]에 접근이 가능했었는데 왜 비슷한 맥락으로 보이는 저 부분은 왜 ReferenceError: accounts is not defined라고 나오는 것인가요...? 도움 주시면 감사하겠습니다.
하단은 작성하였던 코드와 오류 메시지입니다.

var Election = artifacts.require("./Election.sol");

contract("Election", function(accounts){
    var electionInstance;

    it("initializes with two candidates", function() {
        return Election.deployed().then(function(instance) {
            return instance.candidatesCount();
        }).then(function(count) {
            assert.equal(count, 2);
        });
    });
});

it("it initializes the candidates with the correct values", function() {
    return Election.deployed().then(function(instance) {
      electionInstance = instance;
      return electionInstance.candidates(1);
    }).then(function(candidate) {
      assert.equal(candidate[0], 1, "contains the correct id");
      assert.equal(candidate[1], "Candidate 1", "contains the correct name");
      assert.equal(candidate[2], 0, "contains the correct votes count");
      return electionInstance.candidates(2);
    }).then(function(candidate) {
      assert.equal(candidate[0], 2, "contains the correct id");
      assert.equal(candidate[1], "Candidate 2", "contains the correct name");
      assert.equal(candidate[2], 0, "contains the correct votes count");
    });
  });

  it("allows a voter to cast a vote", function() {
    return Election.deployed().then(function(instance) {
      electionInstance = instance;
      candidateId = 1;
      return electionInstance.vote(candidateId, { from: accounts[0] });
    }).then(function(receipt) {
      return electionInstance.voters(accounts[0]);//생성된 유권자 매핑을 읽을 것임
    }).then(function(voted) {
      assert(voted, "the voter was marked as voted");//투표 유무를 부울 값으로 보여줌
      return electionInstance.candidates(candidateId);
    }).then(function(candidate) {
      var voteCount = candidate[2];
      assert.equal(voteCount, 1, "increments the candidate's vote count");
    })
  });


#자바스크립트 isnan #자바스크립트 isempty #자바스크립트 isnumber #자바스크립트 isnull #자바스크립트 isarray #자바스크립트 is not defined #자바스크립트 is not a function #자바스크립트 is #자바스크립트 isinteger #자바스크립트 isnumeric

profile_image 익명 작성일 -

accounts 변수의 적용 범위가 끝나서입니다.

작성된 소스를 살펴보면 contract(..) 부터 정의된 accounts 변수가 13라인에서 괄호를 닫으면서 끝나는데요.

괄호를 닫는 지점이 잘못된 것이 아닌가 생각됩니다.

13라인의 아래 코드는 삭제되어야 할것 같습니다.

});

질문 is not defined at...

... 자바스크립트 파일에 작성한 changeColor 이벤트는 아래와 같습니다. 그리고 시간을 입력받는 input 란에 숫자를 입력했을 때 뜨는 오류입니다. 저 함수를...

name 'pd' is not defined 오류가...

주피터노트북에서 NameError: name 'pd' is not defined 라는 오류가 뭐죠,,, 왜 뜨는건가요? NameError: name 'pd' is not defined 라는 오류가 뜨는 이유는 'os'라는 모듈...

require is not defined.

... html 접속시 저 행에서 "require is not defined." 오류가 발생 하는데... 참고로 Node.js는 PHP와 같은 서버에서 사용할 수 있는 자바스크립트 언어입니다....

name 'os' is not defined 라는 오류가...

주피터노트북에서 NameError: name 'os' is not defined 라는 오류가 뜨는데 뭐가 문제인걸까요? NameError: name 'os' is not defined 라는 오류가 뜨는 이유는 'os'라는...

파이썬 오류 (name is not defined)

분명히 a 변수 지정했는데 왜 자꾸 변수지정이 안되었다고 오류가 날까요..? 화면을 보면 지금 프로그램을 터미널에서 실행한 것이 아니고, 터미널 내에서 파이썬 인터프리터를...

자바스크립트 return문 defined 에러

책보며 자바스크립트를 공부중 책과 같게 작성해도 오류가 떠 질문드립니다. function sum(num1,num2)... result is not defined 라고 뜹니다. Inner 와 out은...