Transform text to uppercase in Scratch

3.4k views Asked by At

My niece is trying to do a school assignment with scratch and asked for some help. Her assignment is to create a script that takes in a password mixed with numbers and lowercase letters and she has to change the letters from lowercase to uppercase. I have never used scratch before.. I tried my best but I'm not sure where I am making the mistake. I set evengroup as the variable containing what would be the password. I created a new function which I based off of something I found online and incorporated that in an iteration of the password on the left. Any ideas?

Scratch Code

3

There are 3 answers

0
ppwater On

Try this:

Answer picture

It had the problem when the string contained an number it doesn't stop, so I fixed it.

and see the discussion on scratch

0
customcommander On

I have defined two custom blocks:

position

Set a variable position$ to the position of character in text. 0 means that given character was not found in given text. We'll use that block to check each character of the password against the set of lowercase letters.

uppercase

Pass each character of the password to the position block. If position$ is not 0 then current character was a lowercase letter and find the corresponding character in the set of uppercase letters. Otherwise keep the current character. The uppercase$ variable accumulates the result of either of these checks.

define position [character] [text]
    set [position$ v] to []
    set [pos_i v] to [0]
    repeat until <<(position$) > [0]> or <(pos_i) > (length of (text))>>
        if <(letter (pos_i) of (text)) = (character)> then
            set [position$ v] to (pos_i)
        end
        change [pos_i v] by [1]
    end
    
define uppercase [text]
    set [uppercase$ v] to []
    set [upp_i v] to [1]
    repeat (length of (text))
        position (letter (upp_i) of (text)) [abcdefghijklmnopqrstuvwxyz]
        if <(position$) > [0]> then
            set [uppercase$ v] to (join (uppercase$) (letter (position$) of [ABCDEFGHIJKLMNOPQRSTUVWXYZ])
        else
            set [uppercase$ v] to (join (uppercase$) (letter (upp_i) of (text))
        end
        change [upp_i v] by [1]
    end
    
when green flag clicked
ask [Enter your password] and wait
uppercase (answer)
say (uppercase$)

enter image description here


If you want to see how this looks in Scratch3, there is a snippet below:

<script src="https://github.com/scratchblocks/scratchblocks/releases/download/v3.5.2/scratchblocks-v3.5.2-min.js"></script>
<pre class="blocks">
define position [character] [text]
    set [position$ v] to []
    set [pos_i v] to [0]
    repeat until <<(position$) > [0]> or <(pos_i) > (length of (text))>>
        if <(letter (pos_i) of (text)) = (character)> then
            set [position$ v] to (pos_i)
        end
        change [pos_i v] by [1]
    end
    
define uppercase [text]
    set [uppercase$ v] to []
    set [upp_i v] to [1]
    repeat (length of (text))
        position (letter (upp_i) of (text)) [abcdefghijklmnopqrstuvwxyz]
        if <(position$) > [0]> then
            set [uppercase$ v] to (join (uppercase$) (letter (position$) of [ABCDEFGHIJKLMNOPQRSTUVWXYZ])
        else
            set [uppercase$ v] to (join (uppercase$) (letter (upp_i) of (text))
        end
        change [upp_i v] by [1]
    end
    
when green flag clicked
ask [Enter your password] and wait
uppercase (answer)
say (uppercase$)
</pre>
<script>
scratchblocks.renderMatching('pre.blocks', {style: 'scratch3'});
</script>

0
RixTheTyrunt On

To make text uppercase, you might just want this:

iUS.svg