Device that greets based on the time

I want to make a kind of device that tells you good night if it's any time between 0:00 and 6:00, good morning if it's between 6:00 and 12:00, or good afternoon if it's between 12:00 and 0:00.

Welcome
Try an if then else statement
To get the time, use the clock component

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps
How to do a lot of basic things with App Inventor are described here: How do you...? .

Also do the tutorials Our Tutorials! to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

Very simple and basic approch with clock

Grt current hr

Then use if then else if combination and print the result in label

When Screen1 Initialize
    Set currentHour local variable to get Clock1.Hour
    If currentHour >= 0 and currentHour < 6
        Set LabelGreeting.Text to "Good Night!"
    Else If currentHour >= 6 and currentHour < 12
        Set LabelGreeting.Text to "Good Morning!"
    Else If currentHour >= 12 and currentHour < 24
        Set LabelGreeting.Text to "Good Afternoon!"
    End If

Perhaps better ?

Between 0000 and 0559
Good Morning
Between 0600 and 1159
Good Day
Between 1200 and 1759
Good Afternoon
Between 1800 and 2359
Good Evening 

1 Like

If you arrange your tests in ascending order, you don't need AND clauses in your elseif ladder.

If < 0600 ...
elseif < 1200 ...
elseif < 1800 ...
else ...

1 Like