Codeyear folks

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.

On Thu, 01 Mar 2012 23:18:34 GMT
GofBorg 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

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/

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/

-----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/

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-----

Second hint: Order matters.

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

And … new problem on the Codeyear site today :slight_smile:

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!