PDA

View Full Version : Codeyear folks



GofBorg
02-Mar-2012, 00:18
Take a look at this and see if you can spot the error.

<code>

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);
}

<code>

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

malcolmlewis
02-Mar-2012, 01:08
On Thu, 01 Mar 2012 23:18:34 GMT
GofBorg <GofBorg@no-mx.forums.opensuse.org> wrote:

> Take a look at this and see if you can spot the error.
>
> <code>
>
> 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);
> }
>
> <code>
>
> It ignores the second else if entirely, not sure why.
> Probably syntax somewhere but haven't been able to find it.
>
>
>
>
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

Ben A L Jemmett
02-Mar-2012, 01:08
GofBorg wrote:
> 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.

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/

Ben A L Jemmett
02-Mar-2012, 01:30
I wrote:
> Are you after a hint, or the answer? If the latter

.... former. I am obviously asleep already. Sorry!

--
Regards,
Ben A L Jemmett.
http://flatpack.microwavepizza.co.uk/

ab
02-Mar-2012, 03:18
-----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+c5JPMe5fpIqVps7oZGbDr tUiLPO2Ebek7Sg
FDTXZnIRemINKzitOQfvIDPT9/mM1MPbaHIkl8T5AdI/lU5nxYmcsWZfRWz0lwUF
XrqQZkK6Thy2+nwnFsNd5+ESSrYazUuv3Kz/AzE4QL8qCz7PqxJEJEqWDpg1iiaV
V+mrW50+9l9aUXluq2DJtzBx+Zy6Xq649UkVqVP4qtXfuxg3if zcl/+bHQXoV2mm
iazMkvNEty911xKQm5OjtHhe8fXvJntBBFx4oa3YRCoqo32jJg MsAwkS1j1+ZS5e
G20a1VrVvXzloyEo078rKK5cWo5KHrgttZqaTccREoMYTWU6g3 RywwY5iI/634J6
hhqrmKVSPn6NAvggA3Glx92uK1+P7k10lG4y1WdT4RRGQBjFUR JGRF9kHjWvSU4U
nyIiP83hnCRFhPI+YeLUBHDpzPtHq90w6jhFUoMkt/w3iXQhvkCCdh9JTTV4cTx6
oiWUZ8di3jfp/mnmeBuu
=ntKs
-----END PGP SIGNATURE-----

GofBorg
06-Mar-2012, 00:03
> Second hint: Order matters.

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

Dave Howe
06-Mar-2012, 10:32
And ... new problem on the Codeyear site today :)

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