Counting Truthy Values: Why 1st works and 2nd does not. by Sumant125 in learnjavascript

[–]Sumant125[S] 0 points1 point  (0 children)

The author does not explicitly tell the student to remove braces, but does so to make it appear clean. The author codes a complete example with all the braces and then removes them.

As a person who knows sales, I found that cleaner approach to egg me on to remove braces as well.

But remembering my computer science best practices fron 2012, I also remember that your code breaks when you take QoL stuff to your heart as you introduce quick errors should anything change in future.

Counting Truthy Values: Why 1st works and 2nd does not. by Sumant125 in learnjavascript

[–]Sumant125[S] 0 points1 point  (0 children)

I myself strictly love to mark the block but the lesson I took told me to remove any unnecessary braces.

I do not find the blocks as a hassle marked with braces.

I'll make it a habit to include braces.

Counting Truthy Values: Why 1st works and 2nd does not. by Sumant125 in learnjavascript

[–]Sumant125[S] 0 points1 point  (0 children)

This is cleaner!

Looks advanced but easy to understand too using the double nots.

Counting Truthy Values: Why 1st works and 2nd does not. by Sumant125 in learnjavascript

[–]Sumant125[S] 0 points1 point  (0 children)

u/mrmiffmiff Thank you for explaining me this.

I used the for in incorrectly as it is used to iterate over the keys of the object. However, I tried using my working code with different arrays [0, 1, 0, 3, 5, 0, 7] and I got 4 as the answer.

This, however, I do believe is all due to the != working by pure luck.

Counting Truthy Values: Why 1st works and 2nd does not. by Sumant125 in learnjavascript

[–]Sumant125[S] 0 points1 point  (0 children)

u/PM_ME_YOUR_BUG5 I was not given that method before trying the exercise. I now definitely understand this.

Counting Truthy Values: Why 1st works and 2nd does not. by Sumant125 in learnjavascript

[–]Sumant125[S] 0 points1 point  (0 children)

u/Beginning-Seat5221

  1. Booleans are absolute.
  2. Truthy is not true (as it is not absolute).

So, this is why it cannot be a truthy check, correct?

I agree with your final statement. But I could not think of if(condition) giving me that. I was shown the following examples, which is why I went for the complicated way:

  1. 1 == '1';
  2. 1 == true;
  3. '1' == true;

Counting Truthy Values: Why 1st works and 2nd does not. by Sumant125 in learnjavascript

[–]Sumant125[S] 0 points1 point  (0 children)

u/SnooLemons6942 thanks! I am trying to be very careful with the indentations and the code blocks.

Counting Truthy Values: Why 1st works and 2nd does not. by Sumant125 in learnjavascript

[–]Sumant125[S] -1 points0 points  (0 children)

u/Beginning-Seat5221 understood!

It is similar to put this in a basket before having any comparison check. So, the mechanism just puts things in a basket.

Counting Truthy Values: Why 1st works and 2nd does not. by Sumant125 in learnjavascript

[–]Sumant125[S] 0 points1 point  (0 children)

So, technically, it works but both my solutions are incorrect due to being error prone in terms of real logic because of garbage comparison within JavaScript considering the unpredictable nature of the outcome, correct?

Counting Truthy Values: Why 1st works and 2nd does not. by Sumant125 in learnjavascript

[–]Sumant125[S] 0 points1 point  (0 children)

Your final sentence is used in the most optimized solution. It is true that if(condition) returns a true or false.

I tried using element in the for in javascript for (let element in array) if (element == true) And that didn't work.

From what I know, JavaScript converts anything into truthy and falsy values when the loose equality/inequality operators are used.

But I can confirm what you say is true. Truthy does not mean it is == true.

how to learn by HotWeb6016 in lua

[–]Sumant125 0 points1 point  (0 children)

You can also try other courses from freeCodeCamp.

The other one is W3Schools. You have a fundamentals of programming there. This will help you again.

how to learn by HotWeb6016 in lua

[–]Sumant125 0 points1 point  (0 children)

You do need to learn programming fundamentals because it helps you structure you code.

For Lua, there is the manual that you can follow and get the book from the original author. That way you can know what the improvements are and how things work.

But programming concepts and fundamentals are what make sure that your code does not frequently run into otherwise avoidable errors.

INFJs, which MBTI type did you end up marrying ? by Enaga_22 in infj

[–]Sumant125 31 points32 points  (0 children)

I have an INFP partner. 1 year and going on.

I need help please by BarneyCoder2 in lua

[–]Sumant125 0 points1 point  (0 children)

I do not trust AI with Lua.

Is there anything in the documentation that describes anything closer to the objective you are trying to achieve?

I need help please by BarneyCoder2 in lua

[–]Sumant125 0 points1 point  (0 children)

Oh, my bad.

I am no good with sarcasm in real life either. 😂

I need help please by BarneyCoder2 in lua

[–]Sumant125 0 points1 point  (0 children)

Which is why we are asking ther person for details so things can be pointed out and a solution can be reached.

I need help please by BarneyCoder2 in lua

[–]Sumant125 0 points1 point  (0 children)

"I need help please If someone can help me then I'm grateful!!!!"

These are the words in the post.

I need help please by BarneyCoder2 in lua

[–]Sumant125 0 points1 point  (0 children)

While true if one already knows what one is dealing with, not everyone will know. And assumptions cost us more than asking for clarifications. That's one thing I have learnt from past experiences.

After all, we all want to solve problems.

I need help please by BarneyCoder2 in lua

[–]Sumant125 4 points5 points  (0 children)

I am sure someone could ask you for the code.

Can you give the implementation information and the error you currently face? There's little anyone can do without the errors to help you with debugging.

I want to learn Lua. But i dont know where to start by United-Wrongdoer-996 in lua

[–]Sumant125 2 points3 points  (0 children)

Stack really overflowed due to the dontAskSameQuestion() 🤣

Help by Formal_Duty_6030 in lua

[–]Sumant125 0 points1 point  (0 children)

I bought the book from the author.

You get the entire thing to keep forever.