# Codeyear folks

**URL:** <https://forums.suse.com/t/codeyear-folks/22290>\
**Category:** Chatting over the Back Fence\
**Created:** [March 2, 2012, 1:18am UTC](https://forums.suse.com/t/codeyear-folks/22290 "2012-03-02T01:18:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![System1](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@System1](https://forums.suse.com/u/System1)\
**Post date:** [March 2, 2012, 1:18am UTC](https://forums.suse.com/t/codeyear-folks/22290/1 "2012-03-02T01:18:34Z")

</div>

Take a look at this and see if you can spot the error.

`

for (index=1;index\<=20;index ++) {  
if (index%3 === 0) {  
console.log(“Fizz”);  
}  
else if (index%5 === 0) {  
console.log(“Buzz”);  
}  
else if (index%3 === 0 && index%5 === 0) {  
console.log(“FizzBuzz”);  
}  
else  
console.log(index);  
}

`

It ignores the second else if entirely, not sure why.  
Probably syntax somewhere but haven’t been able to find it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [March 2, 2012, 2:08am UTC](https://forums.suse.com/t/codeyear-folks/22290/2 "2012-03-02T02:08:41Z")

</div>

On Thu, 01 Mar 2012 23:18:34 GMT  
GofBorg [GofBorg@no-mx.forums.opensuse.org](mailto:GofBorg@no-mx.forums.opensuse.org) wrote:  
[color=blue]

> Take a look at this and see if you can spot the error.
> 
> `
> 
> for (index=1;index\<=20;index ++) {  
> if (index%3 === 0) {  
> console.log(“Fizz”);  
> }  
> else if (index%5 === 0) {  
> console.log(“Buzz”);  
> }  
> else if (index%3 === 0 && index%5 === 0) {  
> console.log(“FizzBuzz”);  
> }  
> else  
> console.log(index);  
> }
> 
> `
> 
> It ignores the second else if entirely, not sure why.  
> Probably syntax somewhere but haven’t been able to find it.
> 
> [/color]  
> elif rather than else if?

–  
Cheers Malcolm Â°Â¿Â° (Linux Counter #276890)  
SUSE Linux Enterprise Desktop 11 (x86\_64) Kernel 3.0.13-0.27-default  
up 4 days 21:14, 2 users, load average: 0.01, 0.02, 0.05  
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [March 2, 2012, 2:08am UTC](https://forums.suse.com/t/codeyear-folks/22290/3 "2012-03-02T02:08:55Z")

</div>

GofBorg wrote:[color=blue]

> Take a look at this and see if you can spot the error.
> 
> ```
> if (index%3 === 0) {
> else if (index%5 === 0) {
> else if (index%3 === 0 && index%5 === 0) {
> else
> 
> ```
> 
> It ignores the second else if entirely, not sure why.[/color]

Are you after a hint, or the answer? If the latter, well, under what  
conditions is the second else-if condition true, and what does that  
imply for the if condition (and, although less relevantly, the first  
else-if condition)? Oh, and for good measure, ponder why I called my  
parenthetical comment less relevant…

(Also, if I should shut up because I’m not part of this Codeyear thing,  
uhm, oops. Sorry.)

–  
Regards,  
Ben A L Jemmett.  
[http://flatpack.microwavepizza.co.uk/](http://flatpack.microwavepizza.co.uk/)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [March 2, 2012, 2:30am UTC](https://forums.suse.com/t/codeyear-folks/22290/4 "2012-03-02T02:30:59Z")

</div>

I wrote:[color=blue]

> Are you after a hint, or the answer? If the latter[/color]

… former. I am obviously asleep already. Sorry!

–  
Regards,  
Ben A L Jemmett.  
[http://flatpack.microwavepizza.co.uk/](http://flatpack.microwavepizza.co.uk/)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [March 2, 2012, 4:18am UTC](https://forums.suse.com/t/codeyear-folks/22290/5 "2012-03-02T04:18:50Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

First hint: If you hit an ‘if’ you never look at the ‘else’.

Second hint: Order matters.

Good luck.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v2.0.18 (GNU/Linux)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org/](http://enigmail.mozdev.org/)

iQIcBAEBAgAGBQJPUC4KAAoJEF+XTK08PnB5HXYP/30XQPymPRR1LOlfy6ueaiYV  
MFvlO2WQR5P7yViHv365RKNT+kv6PedvS4etHQbL7jc6v7/VgCtzNqPs6L01KStn  
tHGpB58XqNEZOW5hWY5h5I/jNlLglx7w8TkaL+Xl0msu8PreKsjYrw/dvuHB9HFF  
ih8KQvbkLjs3s447JddRge94jj50+c5JPMe5fpIqVps7oZGbDrtUiLPO2Ebek7Sg  
FDTXZnIRemINKzitOQfvIDPT9/mM1MPbaHIkl8T5AdI/lU5nxYmcsWZfRWz0lwUF  
XrqQZkK6Thy2+nwnFsNd5+ESSrYazUuv3Kz/AzE4QL8qCz7PqxJEJEqWDpg1iiaV  
V+mrW50+9l9aUXluq2DJtzBx+Zy6Xq649UkVqVP4qtXfuxg3ifzcl/+bHQXoV2mm  
iazMkvNEty911xKQm5OjtHhe8fXvJntBBFx4oa3YRCoqo32jJgMsAwkS1j1+ZS5e  
G20a1VrVvXzloyEo078rKK5cWo5KHrgttZqaTccREoMYTWU6g3RywwY5iI/634J6  
hhqrmKVSPn6NAvggA3Glx92uK1+P7k10lG4y1WdT4RRGQBjFURJGRF9kHjWvSU4U  
nyIiP83hnCRFhPI+YeLUBHDpzPtHq90w6jhFUoMkt/w3iXQhvkCCdh9JTTV4cTx6  
oiWUZ8di3jfp/mnmeBuu  
=ntKs  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [March 6, 2012, 1:03am UTC](https://forums.suse.com/t/codeyear-folks/22290/6 "2012-03-06T01:03:36Z")

</div>

> Second hint: Order matters.

Ah ha…Got it.  
Light is on.  
Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/suse/original/2X/5/5012ba89e3ffb5220dac47d5ea0ba032e2fe1cb6.png) [@system](https://forums.suse.com/u/system)\
**Post date:** [March 6, 2012, 11:32am UTC](https://forums.suse.com/t/codeyear-folks/22290/7 "2012-03-06T11:32:58Z")

</div>

And … new problem on the Codeyear site today 🙂

Week 2: Build a Taxi Fare Calculator  
Keep up with your coding by finishing this weekÂs lessons. There are  
thousands of other people working on this week’s courses with youÂyou  
will all build a calculator that tells you how much a taxi ride costs!
