I am completely stuck

OK, I answered my own question. Apparently the .click method above is no longer the preferred method and perhaps that is why it was causing unpredictable results with my code. I changed it to the following and now it works:

$(document).on('click', '#addButton', function(){
        fruits.push($("#newFruit").val());
    });
1 Like

so im stuck on prolly the simplest thing,
i useing a mac for the first time and i cant get the path rite to display an image.
my image is in the same foler as the website.html file.

1 Like

Hey @arthur, hope you are great!

Could you please share your code so we can review it in order to help you?

You can use the “Preformatted Text” Button to encapsulate any kind of code you want to show.


function formatText(){

let words = “I’m a preformatted Text box, Please use me wisely!”

}

prefromatted_text-animated

Carlos Z.

In the javascript programming section:
Javascript Programming / Reading Assignment & Quiz: Variables

Lesson 6: Reading Assignment & Quiz: Variables

My question:
Though the quiz section is working fine, there is no link to direct me to the required reading. Where can I find the article/book to read chapter 1?


"Reading Assignment & Quiz: Variables

Javascript Programming

In this reading exercise you’re going to learn about the core building stone of every programming language - namely variables. Variables store pieces of information.

Read Chapter 1 (page 10-20) .

Answer the quiz."

1 Like

In the book which is suggested at the beginning of the course Eloquent JS, book need it

Lesson instructions

Read Chapter 1 (page 10-20).

Answer the quiz.

Carlos Z.

Thanks Carlos, got confused. I appreciate the clarification!

B

1 Like

These videos are GREAT. I’ve nearly watched the whole series of CS50, chose 2017 & watched a couple others too, really informative & great background to programming!! Highly recommend anyone new to programming check them out.

1 Like

Hello @thecil,
I am coding a smart contract to create a list of football team members. I am trying to create getPlayerList to get a list of team members by using the index of array playerList. However I get an error. Please can you help.

pragma solidity >=0.4.0 <0.7.0;

contract FootballTeam {
    
    struct Player {
        string name;
        uint jerseyNumber;
        uint age;
        string nationality;
        string playingPosition;
    }
    
    mapping (address => Player) public players;
    
    Player[]public playerList;
    
    function setPlayer(string memory name, uint jerseyNumber, uint age, string memory nationality, string memory playingPosition) public {
        address creator = msg.sender;
        
        Player memory newPlayer;
        newPlayer.name = name;
        newPlayer.jerseyNumber = jerseyNumber;
        newPlayer.age = age;
        newPlayer.nationality = nationality;
        newPlayer.playingPosition = playingPosition;
        
        players[creator] = newPlayer;
        playerList.push(newPlayer);
        
    }
    
    function getPlayer() public view returns (string memory name, uint jerseyNumber, uint age, string memory nationality, string memory playingPosition) {
        address creator = msg.sender;
        return (players[creator].name, players[creator].jerseyNumber, players[creator].age, players[creator].nationality, players[creator].playingPosition);
    }
    
    function getPlayerList()  public view returns (string memory name, uint jerseyNumber, uint age, string memory nationality, string memory playingPosition) {
        return playerList[index];
    }
}
1 Like

Hey @oneworldcoder, hope you are great.

check your getPlayerlist return a lot of values, while the returned value in the function body just return a indexed result which you dont know the variable type, which is not the correct way to return it because your function must return a bunch of values from different variable types (string memory name, uint jerseyNumber, uint age...).

you might have to use the keywords pragma experimental ABIEncoderV2;, you will receive a warning from remix because this feature should not be used in production (deploying an SC on main net without erros/bugs), but is the only way for now to get a struct values from an array.

After it, your function should look like this:

    function getPlayerList()  public view returns (Player [] memory) {
        return playerList;
    }

It will return a tuple of values from the array, thanks to the ABIEncoder, now for production, that could not be the best solution to save multiple variables from 1 account (I guess you are trying to set multiple players from 1 user), maybe ERC721 or ERC1155 is a best approach.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

2 Likes

Hi @thecil,

I am creating a smart contract to organise a list of candidates for Elections. I want different people to add their candidates but I want the creator to get a list of all candidates. For this I created getCandidateList(). When I call getCandidateList() I get tuple(string,uint256,uint256)[] but do not get a list of candidates. Please help me.

pragma solidity >=0.4.0 <0.7.0;
pragma experimental ABIEncoderV2;


contract Election {

    struct candidate {
        string name;
        string politicalParty;
        string state;
        uint age;
        uint height;
    }
    
    candidate[] public candidateList;
    
    mapping(address => candidate) public candidates;
    

    function setCandidate(string memory name, string memory politicalParty, string memory state, uint age, uint height) public {
        address creator = msg.sender;
        
        candidate memory newCandidate;
        newCandidate.name = name;
        newCandidate.politicalParty = politicalParty;
        newCandidate.state = state;
        newCandidate.age = age;
        newCandidate.height = height;
        candidates[creator] = newCandidate;
    }
    
    function getCandidate() public view returns (string memory name, string memory politicalParty, string memory state, uint age, uint height) {
        address creator = msg.sender;
        return (candidates[creator].name, candidates[creator].politicalParty, candidates[creator].state, candidates[creator].age, candidates[creator].height);
    }
    
    function getCandidateList() public view returns (candidate [] memory) {
        return candidateList;
    }

    
}

Hey there. Wondering if anyone can help me. I have truffle set up with Ganache. I am running tests on my solidity contract that involve sending ether to the contract and withdrawing it from the contract. Funny thing is my tests are PASSING, but when I look, none of the transactions are going to or coming from the actual address of my deployed contract as shown in Ganache. They are interacting with some contract address that doesn’t seem to exist. For example, the actual contract address is: 0x683EB77121Ab6A40cAE6BD78001E5eD95dbC8872 but the mystery contract address is: 0xe0107F0a6210A7200636F3D15Ee0a3741Fe815F6
Any idea how this can be?

You can see more info on this on my stackexchange post, but I haven’t seen much help there figuring this out: https://ethereum.stackexchange.com/questions/89917/deployed-contract-address-in-truffle-does-not-match-ganache/89921?noredirect=1#comment110387_89921

OK, some more info… this is not an issue with only this project. I just went back and tried with another project that we did on my solidity course. The exact same issue is there. The transactions are going to a different address than the stated contract address in truffle and ganache. I just didn’t notice it before.

So this issue is a deeper on between truffle and ganache - not about my project.

Can anyone else confirm on any project of theirs whether the contract shown on individual transactions in ganache is the same as the contract address shown on the contract tab in ganache?

hey @oneworldcoder

You are not pushing your struct into the array.
Push newCandidate to the array when you setCandidate

cheers
Dani

1 Like

your not understanding my question,im not having any problems witth any code.
please read my post

Hey guys. I’m really enjoying the course. The only issue I’m having is some of the ways it’s structured. It’s a little confusing to me. Like the practice exercises - more variables section. It seems that some of what’s on there has not been covered and I can check the solution and figure how to get the answer from there, but I can’t figure out the reasons for why I’m doing it. Am I supposed to be checking google and researching it on my own? And if so, I’m confused as to why there’s not something that covers the questions that are being asked after doing the research. Please help, thank you.

2 Likes

Hey @mraustinhicks, hope you are good.

Now the practice exercises are made just to practice basic knowledge on JavaScript (like how to use the console.log), some of our students want more basic exercises to practice, so we made them, there are no mandatory for the course, their just for practice.

Believe me or not, even the most advance programmers have to time to time use google to research by their own, so it is good practice to: If i dont know something, i can google it.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

1 Like

Hi guys,
I really need help at this point. it always gives me unexpected token else. what i have to do to fix it?

Hello,

I am trying to make a smart contract for a calculator. Something is wrong in my code. I am unable to use floating-point numbers. Please can someone correct my mistake? Thank you.

pragma solidity >=0.4.0 <0.7.0;
pragma experimental ABIEncoderV2;

contract Calculator {

  uint result;
  

  function enterNumber(uint num) public {
      result = num;
  }

  function getResult() public view returns (uint) {
    return result;
  }

  function addToNumber(uint num) public {
    result += num;
  }

  function substractNumber(uint num) public {
    result -= num;
  }

  function multiplyWithNumber(uint num) public {
    result *= num;
  }

  function divideByNumber(uint num) public {
    result /= num;
  }

}
1 Like

The link for the pdf book doesn’t work has anyone got a new one? Thanks

1 Like

Hey @jad, hope you are good.

Are you typing the code directly on the console? because the exercises said to create a file with name “hight.js” and then run it to show the result in the console.

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.