# 15- Exercise 6- Count Truthy

**URL:** https://forum.codewithmosh.com/t/15-exercise-6-count-truthy/6428
**Category:** JavaScript
**Created:** [July 29, 2021, 7:29am UTC](https://forum.codewithmosh.com/t/15-exercise-6-count-truthy/6428 "2021-07-29T07:29:07Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Hamza-Noah](https://avatars.discourse-cdn.com/v4/letter/h/858c86/32.png) [@Hamza-Noah](https://forum.codewithmosh.com/u/Hamza-Noah)
#### Post date: [July 29, 2021, 7:29am UTC](https://forum.codewithmosh.com/t/15-exercise-6-count-truthy/6428/1 "2021-07-29T07:29:07Z")

</div>

> **[15- Exercise 6- Count Truthy](https://codewithmosh.com/courses/javascript-basics-for-beginners/lectures/5088016)**
>
> Master the fundamentals of JavaScript - The language behind millions of websites & apps

Hello I am trying to solve the exercise here but the code is not working so can anybody tell me whats the problem

Here is my solution

const falsei = ["", 0, false, null, undefined];

console.log(countTruthy(falsei));

function countTruthy(arr) {

let count = 0;

for (let value of arr) {

```
if (value) count++;

```

}  
return count;  
}

---

<div class="post-metadata">

### Author: ![EpikNohVuh](https://avatars.discourse-cdn.com/v4/letter/e/c68b51/32.png) [@EpikNohVuh](https://forum.codewithmosh.com/u/EpikNohVuh)
#### Post date: [July 29, 2021, 10:07am UTC](https://forum.codewithmosh.com/t/15-exercise-6-count-truthy/6428/2 "2021-07-29T10:07:10Z")

</div>

1. the parameter and argument do not match.
2. you have a truthy statement of “value”, and it should be a falsey statement of !value.

```auto
const falsei = ["", 0, false, null, undefined];

console.log(countTruthy(falsei));

function countTruthy(falsei) {

    let count = 0;

    for (let value of falsei) {

        if (!value) count++;

    }
    return count;
}

```

---

<div class="post-metadata">

### Author: ![Hamza-Noah](https://avatars.discourse-cdn.com/v4/letter/h/858c86/32.png) [@Hamza-Noah](https://forum.codewithmosh.com/u/Hamza-Noah)
#### Post date: [July 30, 2021, 1:53am UTC](https://forum.codewithmosh.com/t/15-exercise-6-count-truthy/6428/3 "2021-07-30T01:53:54Z")

</div>

1 why the parameter and the argument should match ?

2 if I had a truthy statement of “value”, and it should be a falsey statement of !value. it will count only the falsy values

---

<div class="post-metadata">

### Author: ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)
#### Post date: [July 30, 2021, 4:47am UTC](https://forum.codewithmosh.com/t/15-exercise-6-count-truthy/6428/4 "2021-07-30T04:47:40Z")

</div>

> [@Hamza-Noah](#):
>
> but the code is not working

Why do you think it’s not working?

---

<div class="post-metadata">

### Author: ![Hamza-Noah](https://avatars.discourse-cdn.com/v4/letter/h/858c86/32.png) [@Hamza-Noah](https://forum.codewithmosh.com/u/Hamza-Noah)
#### Post date: [July 31, 2021, 2:30am UTC](https://forum.codewithmosh.com/t/15-exercise-6-count-truthy/6428/5 "2021-07-31T02:30:25Z")

</div>

That is why I am asking here

---

<div class="post-metadata">

### Author: ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)
#### Post date: [July 31, 2021, 7:14am UTC](https://forum.codewithmosh.com/t/15-exercise-6-count-truthy/6428/6 "2021-07-31T07:14:17Z")

</div>

> [@SAM](#):
>
> > [@Hamza-Noah](#):
> >
> > but the code is not working
> 
> Why do you think it’s not working?

> [@Hamza-Noah](#):
>
> That is why I am asking here

Please clarify “not working”. Do you get an error message? Do you get other results than you expected?

The code is working for me so you need to explain your problem with it.

---

<div class="post-metadata">

### Author: ![EpikNohVuh](https://avatars.discourse-cdn.com/v4/letter/e/c68b51/32.png) [@EpikNohVuh](https://forum.codewithmosh.com/u/EpikNohVuh)
#### Post date: [July 31, 2021, 9:19pm UTC](https://forum.codewithmosh.com/t/15-exercise-6-count-truthy/6428/7 "2021-07-31T21:19:56Z")

</div>

```auto
const falsei = ["", 0, false, null, undefined]; //creating a variable.

console.log(countTruthy(falsei)); // console.log is writing to the console. (countTruthy(falsei) is executing the function (to the console).

function countTruthy(falsei) { // calling the parameter, located outside of the function.

    let count = 0;

    for (let value of falsei) { //since the variable was called, it can be used inside the function.

        if (!value) count++;

    }
    return count;
}

```

You may need to find outside resources to explain ‘things’ better. Such as argument/parameter. Which Mosh did explain in one of his videos. Also, truthy/falsey. And many other things. You will not be able to watch the video once and ‘take it all in’. Review… review… review! Redo the quizzes… redo the quizzes… redo the quizzes. Understand what the program is trying to do.

---

<div class="post-metadata">

### Author: ![Hamza-Noah](https://avatars.discourse-cdn.com/v4/letter/h/858c86/32.png) [@Hamza-Noah](https://forum.codewithmosh.com/u/Hamza-Noah)
#### Post date: [August 1, 2021, 10:39am UTC](https://forum.codewithmosh.com/t/15-exercise-6-count-truthy/6428/8 "2021-08-01T10:39:27Z")

</div>

special thanks for your advice I will do I really appreciated

---

<div class="post-metadata">

### Author: ![Hamza-Noah](https://avatars.discourse-cdn.com/v4/letter/h/858c86/32.png) [@Hamza-Noah](https://forum.codewithmosh.com/u/Hamza-Noah)
#### Post date: [August 1, 2021, 10:40am UTC](https://forum.codewithmosh.com/t/15-exercise-6-count-truthy/6428/9 "2021-08-01T10:40:09Z")

</div>

I found it is working now thank you SAM
