Daily Challenge #2

I said in the first Challenge.

without telling the challenge.

Well, since i started this i will do the opposite here. :grin:

Questions:
Why does this not work?
What has to change to make it work, and why is that?
Can you do this another way?

image

5 Likes

Ok, @Peter
Do I need to figure out a proper bug-free solution?

Edit: I got the challenge, can i tell it?

I feel it’s syntactically right, but semantically incoherent.

The output will be what’s desired, but the blocks are slightly misplaced so variables don’t contain what they say they do.

@Peter am I right?

1 Like

Yes of course you can. One must be the first.

Not exactly. It works as it should but you have to replace one block.


Here’s what I came up with. Not exactly the most efficient, but certainly very hard to understand :joy:

5 Likes

Got it :+1:

4 Likes

is it about switching blocks of “then” and “else” part of if-else

1 Like

Here’s how it works:

A loop is run 10 times (once for every numeric digit).
In each iteration, every occurrence of the current digit is removed from the text and replaced with an empty string. (Text “H3e00llo12” -> “H3ello12” in the first iteration)

A nested loop is executed “X” number of times, where “X” is the difference between the lengths of the text before and after replacement. (In the example above, 10 - 8 = 2)

In each iteration of the nester loop, the current digit is appended to the splitText variable. (In the first iteration, splitText becomes “00”)

Once execution moves out of the loop, the rest of the text (which is guaranteed to have no digits now) is appended to splitText.

(The final value of splitText should look like “00123-Hello”)

5 Likes

@Peter I’ve added the *daily-challenge tag to this topic so that we can, in the future, find all daily challenges easily.

6 Likes

Nope :grin:

1 Like

These are the things you have to do…

And to answer…

2 Likes

I guess no new answers will follow.

You have to replace the “is string?” block with a “is number?” block.

image

Look at the blocks below how Kodular interprets strings and number with the different blocks. The number block accepts numbers in textboxes and numberboxes. The string block only accepts numbers in a textbox not a numberblock.

That’s why when i wanted to sort letters and numbers, for instance

a1b2c3 into abc - 123

i had to make sure that a number would be treated like a number.

8 Likes

Why you are not in teacher’s group? Apply today:wink:
And keep up the good work:+1:

4 Likes

Who wants a crazy teacher? :crazy_face:

5 Likes

A crazy teacher has some crazy knowledge…!! :star_struck:

6 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.