Maximum call stack exceeded error

Lol, it sounded like ternary. I just wonder how it’s possible to write a boolean in along code so it’s still makes one line of it. Weird. Happens, when you don’t know all the fundamentals or at least approaches of this language

What about practical excercises for this language? Can you recommend any web page?

Join repl.it and log in. In your profile menu select Learn/Teach and choose JavaScript. That should give you a number of exercises to solve.

The rudiments should be learned up front, not in a project. Programs are essentially a bundle of smaller programs, each with simple purpose roles that contribute to the overall program. Learn to write small, purpose based functions and prograrms so that when it comes to a larger project you can visualize it as the smaller parts and build each component in a stand alone environment. Write, write and re-write until the function is error free and resistant to errors.

You are right. I feel like, it’s too much robust theory to be and unconnected excercises of which I am getting tired already.

repl.it has a weird interface. When I tried to use: return Math.pow(radius, 2)*Math.PI; the result was undefined lol

I don’t see my mistake in here. In theory, it should have been correct…

When I stuff the similar code to VS code, it doesn’t show any syntax errors…

The faulty part of the VS code is taht I can’t get the debug to work. I am like having no clue what to do with it.

Is radius set to a value?

 > radius = 1
<- 1
 > Math.pow(radius, 2) * Math.PI
<- 3.141592653589793

BTW

Here is an example of a ternary expression…

function checkAge(name, age) {
  return age < 21 ? `Go home, ${name}!` : `Welcome, ${name}!`;
}

var output = checkAge('Adrian', 22);
console.log(output);    // Welcome, Adrian!

Ternary means three parts.

condition or state ? value if true : value otherwise;
                   ^               ^
               operator        separator

There was just the parameter radius as an argument. The test must have needed to define the radius when calling the function. Somehow it showed undefined…

As all variables must be defined before we poll them. The computer does not know what a radius is and cannot assign arbitrary values to an undefined variable.

so I have to declare that radius is an integer like radius = new int?

Unlike C or Java, variables in JavaScript are typecast on the fly, and determined by the value.

let radius = Math.PI;

The type will be float since PI is a float.

let radius = 5;

The type will be integer since 5 is an integer. That is how we assign type, by simply assigning a value. That also means we can change the data type on the fly just by changing the value the variable points to.

Bottom line, we must define variables before using them in our code.

A variable can be defined inside the parameter of a function.

function areaOfCircle(radius) {
    return Math.pow(radius, 2) * Math.PI;
}

Now whatever type we pass to the function will be the type on the parameter.

console.log(areaOfCircle(Math.sqrt(3))    // 9.424777960769378

console.log(areaOfCircle(1)               // 3.141592653589793

Yeah it’s weird that I don’t know what will the radius be, it’s so unrealistic I make a console. log in order to say the computer the number.

What is the problem you are working on? Clearly it’s a geometry question involving area of a circle for which we have one known, the radius, one unknown, the area, and a constant, PI. The area varies directly with the square of the radius times PI.

It’s just an excercise I was messing with, there is no real life point with it. Developing the logical side and function writing perhaps. I just wonder why it’s so illogical

Can we see the problem? In geometry there is very little that is illogical. It’s an analysis tool that for centuries we have been able to rely upon in all number realms, including imaginary numbers.

y = f(x)

describes a dependent variable (y) as it relates to an independent variable (x). y is said to be a function of x. In our case the function is,

f(x) = x**2 * c

where x is the radius of a circle, and c is a constant, PI. So,

 y = r**2 * PI

Here we know that y represents the area of a circle, so we could write,

circle_area = radius ** 2 * PI

Programming it can be illogical and non life-oriented, when I have to sign a random value to make the piece of code work til a test overwrites the value with it’s own

You’re describing a problem without showing it to us. That is illogical. Please spell it out so we can see for ourself where the confusion may arise.

Yeah. I already closed the excercise. Visual studoi code has:

function areaOftheCircle (radius) {

    return Math.pow(radius,2)*Math.PI;
}

That is what is known as a pure function. It always gives a result in direct proportion to what is passed to it through the parameter.

console.log(areaOftheCircle(1))    // 3.141592653589793

Math.pow() if the power function, and in this expression it is a method of the Math object which is dedicated to working with mathematical functions and constants.

Given a value (a base) and a power (the exponent, 2), the function will raise the value to the power of the exponent.

radius ** 2

Yeah, but why the h… it does give me a result of undefined? Do I need to declare the radius as a local variable or do I need to use console.log radius smth or is there any 3rd option?

The radius is defined by the value we pass to the function. It’s a number literal in the examples from earlier.

Math.sqrt(3)
Math.PI
1

Each of those are numbers that represent the radius of a circle. The radius variable is defined in the function parameter.

Yeah. That’s what I thought too. Somehow the environment there told me undefined after the test had launched. In my logic, it should have worked, when the test environment will pass in a value to radius argument. Somehow it still said undefined. What to do in that case? Declare the radius in local level somehow?