Done everything right, but still won't get pass.

Alphabetize

puikaaa
8 years ago | edited 8 years ago

0

Hi everybody.

I used PHP to write a code that will sort the text, but when entered (either withing 5 seconds or with JavaScript turned off) I still can’t pass the test.

Here is the code:
```<?php
$string = “too, you, likely, with, every, who, his, than, neither, while, however, most, get, was, there, which, may, some, says, your, able, into, any, why, after, only, either, whom, then, these, her, other, can, when, ever, does, not, might, that, about, did, should, say, were, must, among, got, cannot, but”;

// Let’s split it and add in array, for easier sort
$array = explode(“, ”,$string);

// Sorting the mess
sort($array);

// Wow, helper vars!?
$i=1;
$col=“”;

// Aaaand.. the output
foreach($array as $word) {
if($i!==1) $col = “, ”;
echo $col . $word;
$i++;
}
?>
```

And the result is:

able, about, after, among, any, but, can, cannot, did, does, either, ever, every, get, got, her, his, however, into, likely, may, might, most, must, neither, not, only, other, say, says, should, some, than, that, then, there, these, too, was, were, when, which, while, who, whom, why, with, you, your

Can you please explain me why the form won’t let me through? Is it a bug? Maybe a typo in my code?
Thank you in advance.

P.S. Really nice project. Of course design makes my eyes bleed, haha. No offense. :)

6replies
4voices
229views
? [bolofecal]
8 years ago

0

You copy the textarea content for your code string? Maybe is take many time. I suggest you learn join(), and msybe translate it to javsscript, and remove the spoiler.

Mugi [Mugiwara27]
8 years ago

0

Did you know that the list of words is not the same every time your reload the level’s page ?
You should, instead of initializing a string with precise words, check the level’s page, take the words, store them into string or array or everything you want and let the rest of the code sorting everything :p

puikaaa
8 years ago | edited 8 years ago

0

Thanks @Mugiwara27 & @bolofecal Yes I just realized each time the textarea changes value. So I guess best way really would be JavaScript. I think now I know what to do :)

P.S. @bolofecal at this point I think for some other beginners It still is a hint, so I’ll leave it there. And aobut join. I know how to use join(), yet I did it oldschool-lazy way. :D

? [bolofecal]
8 years ago

0

You’re welcome. If coding challenges and captcha doesn’t change will be vry easy complete it.

derpderp [rsyed]
5 years ago | edited 5 years ago

0

Hmm I think I am having the same problem where my word list is exactly initialized and I know that is a poor way of handling this challenge b/c the word list changes every time.

The way I sort the array currently uses: sort() with the double quotes for each element. I am trying to find another way to sort the array without having quotes or if the move would be to create a function that would put double quotes into the array, then sort it, then remove it, but I think that I am overthinking the problem..

Can you elaborate on what you meant by checking the level’s page, taking the words and storing that into a array?

(Working in JS here)

Mugi [Mugiwara27]
5 years ago

0

I’ve PMed you to take a closer look at what you don’t get and to avoid possible spoiler :)

You must be logged in to reply to this discussion. Login
1 of 7

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss