Not able to understand - in java

Not able to understand - in java
0

#1

Not able to understand

Basic JavaScript: Return Early Pattern for Functions
When a return statement is reached, the execution of the current function stops and control returns to the calling location.

Example

function myFun() {
console.log(“Hello”);
return “World”;
console.log(“byebye”)
}
myFun();
The above outputs “Hello” to the console, returns “World”, but “byebye” is never output, because the function exits at the return statement.

Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.

Hint
Remember that undefined is a keyword, not a string.


#2

What don’t you understand? Is this a challenge? Can you post the link? Or the actual code you don’t understand?


#3

i am not able to understand, what code is trying to tell and how to complete the challenge?

Here is the link : https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/return-early-pattern-for-functions


#4

The function you start with is below:

// Setup
function abTest(a, b) {
  // Only change code below this line
   
  // Only change code above this line

  return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

The instructions are:

Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.

Based on the instructions you will need to write some kind of if statement and the code block you want to execute when the if statement condition is true. You will need to write 1 to 3 lines of code to accomplish this task.


#5

Randall gives you a good explanation on how to solve the challenge, but you have to be more specific on what you don’t understand.

In a function when there is a return statement, and that function reaches the return statement it returns what lever you tell it to and quits. So for example

Function number() {
Var num=5;
Return num;

So for the above the function has a variable that gets set to 5, and then the function returns that number. So he function number now has a value of 5

If you tried to add anything after that the code would not be reached because of the return statement, because it would quit the function. Make sense? I’m just grasping at what you said you don’t understand