I am completely stuck

Guys, I am stuck on the first step, and that’s I cannot even get ATOM to work on my MAC laptop. I am running the latest OS. It’s saying " You can’t open the application “Atom” because the Classic environment is no longer supported.

And safari then proceeds to tell me no application can open it?

EDIT: Resolved. So if this was my first test into the programming life for trouble shootings, good job guys haha.

1 Like

this declaration is incorrect, it should be var num_rows = 7 .

Carlos Z

Hey @Alfred_Castro, hope you are well.

Please take a look in this old reply which explain in details that exercise.

Carlos Z

npm install is a command that you use to install all the dependecies from a package.json file, it should work same way in windows or appel (brew terminal i think it is on apple).

Carlos Z

Hey @chen, hope you are great.

Could you also please share the same code but with the head and html tags? in the code you share, its start with the body tag, so the scripts and meta tags which are contained in the head tag are missing.

Carlos Z

@thecil , @abuga , @malik ,
i’ve found a workaround for this (problem from the functions exercises at the end of this course), but i’m really confused as to why it returns 0; when i’m debugging it, the word[character] loops as expected, then when it gets to the letter of interest, it’s expected to add 1 to “accumulat”, but simply doesn’t. it sees the expression of interest as true, then just doesn’t execute the next bit of code (accumulat+1)…

i’ve used for/else more explicitly, i’ve tried various semi-colon and parentheses placements, removed the third = operator, and i finally found a work around using a totally different function (regexp), but this is just really flummoxing me… especially because it’s part of the solution suggested in the answer key…have you any input??

function letterCount(word, letter) {
let accumulat = 0;
for (character in word) {
word[character] === letter ? accumulat+1 : 0
}
return accumulat;
}

or another substitute for the insides:
let accumulat = 0;
for (i=0; i<word.length; i++) {
if (word[i] == letter) {accumulat+1;}
}
return accumulate;

Thanks for any input and for your guys’s diligence around here; i’m impressed at your work loads accomplished.

p.s. on a whole separate nota bene: problem 35 has a notable issue of spaces in the letter strings stopping the sorting without pre-cleaning or requiring more code than what’s listed in the answer.

1 Like

How do you get the white preview screen to show up next to your work in Atom? I tried control/shift/H like I found on Google but that didn’t do anything.

Hey @thecil, Just an issue I’m facing while calling a function to get the balances of token addresses passed. I can’t happen to figure out the solution.
Trying this contract in remix-

// SPDX-License-Identifier: MIT
pragma solidity >0.4.22 <= 0.9.0;
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';

contract MainContract{

  struct Token {
    address _tokenAddress;
    uint balance;
}
  
  function getBalances(address _address,address[] memory _tokens) view public returns(Token[] memory){
    uint len = _tokens.length;
    Token[] memory tokenBalances = new Token[](len);

    for(uint i = 0; i<len ; i++){
        uint bal = IERC20(_tokens[i]).balanceOf(_address);
        tokenBalances[i] = Token(_tokens[i], bal);
    }

    return tokenBalances;
  }
}

Input: _address: wallet Address
_tokens: an array of token addresses

Error: call to MainContract.getBalances errored: Error encoding arguments: Error: expected array value (argument=null, value="[‘0xd9145CCE52D386f254917e481eB44e9943F39138’]", code=INVALID_ARGUMENT, version=abi/5.5.0)

1 Like

You might need a mapping for it, the struct itself does not contain or save any data, is just an structure of an object, creating a mapping like mapping(address => Token) tokens might do the trick to save the data of each token, then you just need the getBalance function to look into the mapping.

Hope this helps :nerd_face:

Carlos Z

1 Like

okay, i get what you’re saying. But for storing data there I’m using array to do the same.

1 Like

Could you share the updated contract? Just want to replicate the issue my self

Carlos Z

1 Like

yup, thanks @thecil.

// SPDX-License-Identifier: MIT;
pragma solidity 0.8.0;
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';

contract MainContract{

  struct Token {
    address _tokenAddress;
    uint balance;
  }
  
  function getBalances(address user, address[] memory tokens) view public returns(Token[] memory){
      Token[] memory tokenBalances;
      for(uint i = 0 ; i < tokens.length ; i++){
        tokenBalances[i] = getBalance(user, tokens[i]);
      }

      return tokenBalances;
  }

  function getBalance(address user, address token) view public returns(Token memory){
    uint balance = IERC20(token).balanceOf(user);
    return Token(token, balance);
  }
}
//["0x9d83e140330758a8fFD07F8Bd73e86ebcA8a5692"]


// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

contract Link is ERC20{
   constructor()ERC20("Chainlink","LINK"){
     _mint(msg.sender,10000 * 10 ** decimals());
   }

}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

contract Sushi is ERC20{
   constructor()ERC20("Sushi Token","SUSHI"){
     _mint(msg.sender,10000 * 10 ** decimals());
   }

}

Ok, so first, I deployed Sushi and Link token contracts, only change i made was to add this into the constructor on each:
_mint(0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2,10000 * 10 ** decimals());
So the deployer and 2nd address of the list in remix will have a balance on each contract of that amount of tokens, (after deployment, i called balanceOf to verify that both addresses have a balance of each).

Last, deploy the mainContract, after it, i use getBalance and the result was showed properly
image

Calling getBalances, the array must be send on this way:

["address1", "address2"]

Your function will fail because of a revert without no pointer to, so the only change i made was to specify the length of the array that you will return, that way, your function was able to return the result of balances based on the struct.

So the function looks like this in order to work.

  function getBalances(address user, address[] memory tokens) view public returns(Token[] memory){
      Token[] memory tokenBalances = new Token[](tokens.length);

      for(uint i = 0 ; i < tokens.length ; i++){
        tokenBalances[i] = getBalance(user, tokens[i]);
      }

      return tokenBalances;
  }

PD: the trick here is to specify the length of the array you will return, basic syntax for it is;

uint _length = 5;
// arrayType[](lengthOfArray)
uint [] exampleArray = new uint[](_length);

Hope this helps :nerd_face:

Carlos Z

1 Like

@thecil
Thanks a lot, Carloz. It worked. :grinning:

1 Like