I am completely stuck

Hey @Tony86, which pdf book do you refer to?

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

Carlos Z.

Hey @oneworldcoder. hope your ok.

Could you please share an screenshot of the console error?

Although i think you cant use float numbers on ethereum, none of their documentations mention about float numbers.

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

Carlos Z.

1 Like

Eloquent JavaScript: A Modern Introduction to Programming the pdf version on the web.

1 Like

Ok you mean from this lesson on JavaScript: https://academy.ivanontech.com/products/javascript-programming-for-blockchain-developers/categories/1708561/posts/5735037

I’ve tried myself and its working good.

https://eloquentjavascript.net/Eloquent_JavaScript.pdf

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

Carlos Z.

Hi again Carlos,
Actually I saved once those files with .js from Atom, right? I felt that there’s something wrong, when I open the page saved with .js it looks like this. what i have to do?

1 Like

Hi @thecil

The transaction runs but for eg five divided by two gives the result 2 (not 2.5).

1 Like

Ok, so basically you have saved your code in a JS file (JavaScript file type), it’s for practicing how to save code to use it later.

If you want to try it, you can create an html file, with a basic html anatomy and import or paste into it.

Here is a basic template for the html file:

<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <!-- 1st way, just import the file,
    it must be on the same folder of your html file-->
    <script src="temp.js" >

    <title>Test Enviroment</title>
  </head>
  <body>

    <!-- 2nd way, Paste inside this tag your javascript code i-->
    <script type="text/javascript">

    </script>
  </body>
</html>

The main idea is that you learn how to save your javascript code into files that can be used later in a future, you will get a much easy to read code and well structured.

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

Carlos Z.

Yes, it is because, you cant use float numbers on ethereum, none of their documentation mention about float numbers.

So only integers allow (which is why you do 5/2 = 2) .

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

Carlos Z.

1 Like

Hi Carlos,

I am trying to make a front end application for the calculator. I am using Javascript and JQuery. In the .html file, I have created id’s to access different functions from the smart contract. But I am unable to access the functions. Please help me.

The Html code is

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title> Calculator</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  </head>
  <body>
    <div id="enterNumber"></div>
    <div id="getResult"></div>
    <div id="addToNumber"></div>
    <div id="substractNumber"></div>
    <div id="multiplyWithNumber"></div>
    <div id="divideByNumber"></div>


    <script>
      $(".enterNumber").empty()
      var result; 
      var num;
      


    </script>

  </body>
</html>

The smart contract for the calculator is

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

Hey @oneworldcoder, hope you are good.

Have you finish the Ethereum Programming 201 Course? because there you will learn how to connect your smart contract with your website, through the web3.js utility.

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

Carlos Z.

Hi Carlos,

I was thinking of practising the concepts of Ethereum 101 before I start Ethereum 201. Do you recommend I finish Ethereum 201?

1 Like

Sorry @thecil i just wanted this clear, when we are doing the exercises are we using atom and saving them as a js file? And when we want to test them we use the chrome console?

1 Like

Hey @oneworldcoder
Now that depends on you, ethereum programming 101 will teach you the basics of the solidity programming, in ethereum programming 201 you will learn more advance code and tools, if you need to practice a little bit more thats ok.

But if you have started already ethereum 201 and you doing ok, i think you should finish it :nerd_face:

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

Carlos Z.

1 Like

Hey @LuckyLouie, hope you are ok.

Now yes, to do exercises you use atom to create the JS file and save it (if you want to), the main goal is that you learn how to save or create your own js files.

To test them you can use the template that I created for you in our last response, and them you can use the console.

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

Carlos Z.

Hello,

I am trying to create a smart contract to accumulate data from an Health App. I get an error in the mapping. Please help.

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

contract HealthApp {

  struct Person{
      string name;
      uint age;
      uint height;
      uint weight;
      uint bmi;
      uint runDistance;
      uint walkDistance;
      uint yogaDuration;
      
  }
  
  Person[] public people;
  
  mapping (address => individual) public owners;
  
  
  function track(string memory name, uint age, uint height, uint weight, uint bmi, uint runDistance, uint walkDistance, uint yogaDuration) public {
      address creator = msg.sender;
      
      Person memory newPerson;
      newPerson.name = name;
      newPerson.age = age;
      newPerson.height = height;
      newPerson.weight = weight;
      newPerson.bmi = bmi;
      newPerson.runDistance = runDistance;
      newPerson.walkDistance = walkDistance;
      newPerson.yogaDuration = yogaDuration;
      owners[creator] = newPerson;
      people.push(newPerson);
  } 
  
  
}
1 Like

Early in the Javascript course I’m told to “run Javascript”, but when I do it is a script so it only shows in the console.

Isn’t it true that the HTML shows on the webpage, but then why would you have script if you wasn’t communicating on the web, except that you were referring to instructing the computer on what to do with particular script…?

I’m referring to lesson #9

Javascript Programming for Blockchain Developers

/

Categories

/

Javascript Programming

/

Practice Exercises - console.log & Variables

I’m getting a bit confused between running the script and seeing results with console.log.

I installed the script runner in Java and noticed packages are not being generated to the account I set up in GitHub, so now I have that question: How to connect Atom properly to Github.

When I used the script runner with an example I found out I need node.js, but I’d rather be connected to GitHub properly before I continue.

Am I getting ahead of myself? Should I just be testing in the console? What do you mean by “running the script” at this point?

Hey @oneworldcoder

This is your mapping:

 mapping (address => individual) public owners;

address (key) to individual (value), but what is “individual” in your contract? where is it?
I think it should be

 mapping (address => Person) public owners;

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

Carlos Z.

1 Like

Hey @Eva, hope you are good.

Yes you are getting quite ahead, the main goal is just to write a quick script and run it on the console of your browser.
For example:

function myScript(){
console.log("this is a test");
} 

then I just have to type in the console myScript() and it will show the result.

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

Carlos Z.

Hi Carlos,

It works now, but I have another issue with the code. When I click on the people array I do not get a list of all the people. How to solve this? Thank you

VM599:1 Uncaught ReferenceError: Console is not defined
    at <anonymous>:1:1
(anonymous) @ VM599:1
Console.log("half of 100 is ${100 / 2}")
VM607:1 Uncaught ReferenceError: Console is not defined
    at <anonymous>:1:1
(anonymous) @ VM607:1
 

Not sure what the error is.
Anyone see it..... before I have no hair left...lol
Thanks for the help in advance.