• Home
  • About
    • Chaeeun Gim photo

      Chaeeun Gim

      Game Development.

    • Learn More
    • Email
    • Twitter
    • Facebook
    • Instagram
    • Github
    • Steam
  • Posts
    • All Posts
    • All Tags
  • Projects
  • Concept Arts

Name tester

21 Mar 2019

Reading time ~1 minute

Control flow enables you to easily add conditions and loops to your programs.
In this task you will create a small program that uses conditions and
loops to output custom messages to users.

Name Tester

Instruction

■It reads a name from the user, and displays back a message.
■ Check if the name entered is your name.
■ If the name is your name or your tutor’s name output the message ‘Awesome name!’
■ Otherwise output the silly name message:

▼Design the process

def main
 name = readName('Enter yours or tutors name: ')
 boolean(name)
end
main


▼Create the funtion for read user name

def readName(prompt)
 puts prompt
 value = gets.chomp
end


▼Create the function for verifying data

def boolean(prompt)
   if (prompt == 'Chaeeun Gim' || prompt == 'William Sun' )
     puts "<" + prompt + ">" + ' is an awesome name!'
   else
     puts "<" + prompt + ">" + ' is a'
     i = 0
     while i < 60
          print 'silly'
          i += i
     end
     puts "\n" + 'name!'
   end
end


codefunction Share Tweet +1