Challenge 48 – It’s Getting Dark in Here
This Challenge involved creating a website home page, whose background color dynamically changes with the time of the day.
A business owner wants to create a website home page, whose background color dynamically changes with the time of the day based upon the following:
Between Midnight and Noon: lightening grey scale between black and white
Between Noon and Midnight: darkening grey scale between white and black
Also, vary the text color so that it contrasts with the background color. For instance, at Midnight, the text color should visible on a black background and at noon the text color should be visible on a white background.
- Write the code necessary to create the appropriate website home page background color and text color, based upon time of day and conforms to the requirements above.
- If the website visitor remains on the homepage, the background color and text color should dynamically update.
- Use Greenwich mean time for the official clock.
The winner of the challenge is Alec Wojciechowski.
|Name||Prize Winner||Good Answer|
Alec’s solutions is as follows:
A slightly different approach from the author:
Data Type Conversion
Often, developers must alter data types for different reasons. For example, converting a set value decimal variable to an int or Integer, the explicit conversion is done as follows.
In the former code-snippet, an explicit conversion is done using a cast operator. In the latter code-snippet, the Convert class is used while the ToInt32() method is invoked to convert a string into an int. Explicit conversions require a cast operator. In addition, the destination and source variables should be compatible. Conversion with the assistance of a helper class such as Convert enables us to convert between non-compatible types. This does not need the use of a cast operator.
Coding Challenge #49
Please stay tuned, SCS Coding Challenge #49 will be published this week. Details will follow. The winner will be awarded based upon the best approach.