Create a Linear Scale with D3

Tell us what’s happening:
I am having trouble with this " The output variable should call scale with an argument of 50. "

Your code so far


<body>
  <script>
    // Add your code below this line
    
    const scale = d3.scaleLinear // Create the scale here
    const output = scale(50); // Call the scale with an argument here
    
    // Add your code above this line
    
    d3.select("body")
      .append("h2")
      .text(output);
  
  </script>
</body>

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0.

Link to the challenge:
https://learn.freecodecamp.org/data-visualization/data-visualization-with-d3/create-a-linear-scale-with-d3

scaleLinear is a method and to call it you must put () after it.

2 Likes

I actually had the same question. Since we store an expression in a variable, we should not invoke it beforehand, but rather use the invocation (parenthesis) when we call the stored expression from the variable.
I wanted to see what d3.scaleLinear and d3.scaleLinear() would log in the Chrome console and here’s what I got:

d3.scaleLinear
ƒ vu(){var t=pu(su,an);return t.copy=function(){return hu(t,vu())},du(t)}
d3.scaleLinear()
ƒ r(n){return(o||(o=i(a,c,f?function(t){return function(n,e){var r=t(n=+n,e=+e);return function(t){return t<=n?0:t>=e?1:r(t)}}}(t):t,s)))(+n)}

I dont have a big experience with ES6, but it seems that the scaleLinear method nests a vu() method, which must be invoked first. Idk why, anyone who has more experience on the topic is welcome to give feedback