# CSP 20-21 U7L07 Level 04

**URL:** <https://forum.code.org/t/csp-20-21-u7l07-level-04/33753>\
**Category:** Coding and Debugging Help\
**Created:** [November 18, 2020, 5:32pm UTC](https://forum.code.org/t/csp-20-21-u7l07-level-04/33753 "2020-11-18T17:32:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jslowbe](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jslowbe](https://forum.code.org/u/jslowbe)\
**Post date:** [November 18, 2020, 5:32pm UTC](https://forum.code.org/t/csp-20-21-u7l07-level-04/33753/1 "2020-11-18T17:32:23Z")

</div>

Hello, I think there’s an issue with the solution code in U7 L07 Level 04:

**Link to the project or level:** This link is to [code.org](http://code.org)’s solution example:  
[https://studio.code.org/projects/applab/JEmsWD7dpcEnLbJvZRT-AKtGL2aKK\_poF1wPcHaNMnQ/view](https://studio.code.org/projects/applab/JEmsWD7dpcEnLbJvZRT-AKtGL2aKK_poF1wPcHaNMnQ/view)  
**What I expect to happen:** “-5 is odd?” should return true, -5 is an odd number and -5%2 equals 1.  
**What actually happens:** “-5 is odd?” returns false instead.  
**What I’ve tried:** The solution code works for the other test cases, just not for -5, and the function formula (number%2) == 1 is correct mathematically.

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![jdonwells](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jdonwells/32/7900_2.png) [@jdonwells](https://forum.code.org/u/jdonwells)\
**Post date:** [November 18, 2020, 5:53pm UTC](https://forum.code.org/t/csp-20-21-u7l07-level-04/33753/2 "2020-11-18T17:53:22Z")

</div>

From the ECMAScript 5.1 definition “The sign of the result equals the sign of the dividend.” Meaning that -5 % 2 will be -1 as per the language specification.

So that means there is a bug in the solution. Here is one of many possible fixes :

```auto
function isOdd (number) {
  return number % 2 == 1 || number % 2 == -1;
}

```

Another:

```auto
function isOdd (number) {
  return Math.abs(number % 2) == 1;
}

```

You should open a bug report.

---

<div class="post-metadata">

**Author:** ![infinitestasis](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/infinitestasis/32/5047_2.png) [@infinitestasis](https://forum.code.org/u/infinitestasis)\
**Post date:** [November 18, 2020, 7:22pm UTC](https://forum.code.org/t/csp-20-21-u7l07-level-04/33753/3 "2020-11-18T19:22:31Z")

</div>

This would work too

```javascript
function isOdd(number) {
    return !!(number%2)
}

```

Number%2 will always return 0 if it’s even  
Since 0 is the only number that is falsy, anything odd would be truthy. The `not not` operator will convert it to a boolean.

Another very short solution is

```javascript
function isOdd(number){
    return number%2!=0
}

```

---

<div class="post-metadata">

**Author:** ![jslowbe](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jslowbe](https://forum.code.org/u/jslowbe)\
**Post date:** [November 20, 2020, 8:09am UTC](https://forum.code.org/t/csp-20-21-u7l07-level-04/33753/4 "2020-11-20T08:09:25Z")

</div>

Excellent, thank you Don for the fast and on-target reply. Keep up the good support, makes a big difference for teachers like me taking up this new course.

---

<div class="post-metadata">

**Author:** ![jslowbe](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jslowbe](https://forum.code.org/u/jslowbe)\
**Post date:** [November 20, 2020, 8:10am UTC](https://forum.code.org/t/csp-20-21-u7l07-level-04/33753/5 "2020-11-20T08:10:43Z")

</div>

Excellent, thank you for the fast and on-target reply, those are clever solutions. Keep up the good support, makes a big difference for teachers like me taking up this new course.

---

<div class="post-metadata">

**Author:** ![kaitie](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/kaitie/32/5526_2.png) [@kaitie](https://forum.code.org/u/kaitie)\
**Post date:** [November 23, 2020, 6:23pm UTC](https://forum.code.org/t/csp-20-21-u7l07-level-04/33753/6 "2020-11-23T18:23:43Z")

</div>

Hi Everyone,

Thanks for the teamwork here! This has been fixed and it will be live online in the next day or two!

Kaitie
