Whether it is possible to begin to program in 5 minutes? We study on rebuses and dates of
Any of the programs provided in the text can be gathered in the Notebook editor, to keep in the form of the file with the HTML expansion, further it is necessary to start the browser double click according to the saved file. Everything, it is enough!
So, we will continue.
Mathematical rebuseswas considered by
In the first part “a magic square“, more precisely a way of its receiving by means of the computer. Let`s review an example of other numerical task shown on the first screenshot. It is necessary to solve a rebus “the FLY / HA = FISH SOUP“ in which each letter corresponds to one figure. It is required to find such figures at which substitution instead of letters expression becomes true.
The way of the decision by means of the computer is very simple: by means of the cycles for we will touch all 9999 options for each of 4 - x the figures entering the word “FLY“. We use 4 variables M, U, H and A for storage of figures from 0 to 9, then mathematically the first can be written down as 1000*M + 100*U + 10*X + And. Numbers HA and FISH SOUP are coded similarly then to check result enough one comparison. The code of the program is shown in drawing, we will not provide the answer of a rebus, readers will be able to find it independently, having executed the program.
Use of lines
the Important aspect of any programming language is work with lines. In any language there are such functions as obtaining length of a line, search of a subline, transformation of a line to number and so forth. Let`s review a simple example of a conclusion of a line in various options.
And at last, the third way of a conclusion which we use - a conclusion of a line upside-down. The code differs from the first option only in one line, we suggest readers to understand a difference independently.
Use of dates
1) var d1 = new Date(1979, 1, 6); - creates object with specified year, in the afternoon and month;
2) var d2 = new Date (); - creates object with the current date and time.
Inside the class Date stores time in milliseconds, we will use it and we will write the simple program by means of which it will be possible to learn the number of days about New year. The getTime function returns time in milliseconds, respectively, to receive a difference of dates, it is necessary to subtract one number from another and to share result on 1000*60*60*24 (the number of milliseconds in days). The code of the program and results of its performance are shown in drawing.
On it we will finish the second part. As homework the following mathematical rebus published on one of the websites is offered to solve - to find the numbers hidden under symbols * for which the following condition of multiplication is satisfied: *** x * 2 * = ** 9*2 * .
Once again we will remind that if at implementation of the program the screen of the browser is empty, so in the program a mistake, and it is necessary to double-check the text.