Pls am confused I've tried my best

Tell us what’s happening:
Describe your issue in detail here.
It keeps showing me orderMyLogic(4) should return the string Less than 5 pls where am I missing something

  **Your code so far**

function orderMyLogic(val) {
if (val < 10) {
  return "Less than 10";
} else if (val < 5) {
  return "Less than 5";
} else {
  return "Greater than or equal to 10";
}

}

orderMyLogic(4);


  **Your browser information:**

User Agent is: Mozilla/5.0 (Linux; Android 9; TECNO CC6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.79 Mobile Safari/537.36

Challenge: Logical Order in If Else Statements

Link to the challenge:

Have you looked at what function returns for that case? You can add console.log(orderMyLogic(4)); at the end, to have it printed in console.

1 Like

It showed me less than 10 in the console

You are asked to change the order of the logic.

Change the order of logic in the function so that it will return the correct statements in all cases.

If val is less than 5 it is also less than 10.


You can think of this in terms of size in the physical world. Let us say you have two sieves one has 10mm holes and one has 5mm holes. If the item going through is small enough to go through the 5mm hole it is also small enough to go through the 10mm hole.

2 Likes

orderMyLogic(val) {
if (val < 10) {
return “Less than 10”;

Your code has stopped executing here because you’ve asked it to return a string (and exit the function call) once a condition has been met

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

function orderMyLogic(val) {
if (val < 10) {
  return "Less than 10";
} else if (val < 5) {
  return "Less than 5";
} else {
  return "Greater than or equal to 10";
}

}
console.log(orderMyLogic(4))

  **Your browser information:**

User Agent is: Mozilla/5.0 (Linux; Android 9; TECNO CC6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.79 Mobile Safari/537.36

Challenge: Logical Order in If Else Statements

Link to the challenge:

To reach the second branch, you need a number that isn’t smaller than 10, but somehow smaller than 5. Can you think of such a number? Because I can’t.

That question is not easy I think it is 4

it is smaller than 10 tho

U mean it should be 5

Did you try switching the order?

Do you understand the example code and what is being shown? Take some time and read the example code, it should give you a good idea of what it is you need to do with your own code.

1 Like

It can also help seeing your code run line by line.
https://pythontutor.com/visualize.html#code= function%20orderMyLogic(val)%20{ if%20(val%20<%2010)%20{ %20%20return%20"Less%20than%2010"%3B }%20else%20if%20(val%20<%205)%20{ %20%20return%20"Less%20than%205"%3B }%20else%20{ %20%20return%20"Greater%20than%20or%20equal%20to%2010"%3B } } orderMyLogic(4)%3B&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=js&rawInputLstJSON=[]&textReferences=false

Thanks but I’ve already passed the test

I don’t understand how you do it

function orderMyLogic(val) {
if (val < 5) {
return “Less than 5”;
} else if (val < 5) {
return “Less than 5”;
} else {
return “Greater than or equal to 10”;
}

}

orderMyLogic(4)

This will work, writing condition in particular also matters a lot.

you need to modify the code to

<REDACTED>

as in given challenge whatever the situation is except 10 the return will always be less than 10

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.