How to prepare for doing homework properly
A good developer is a person who not only solves complex problems but also knows how to think outside the box. They must have certain qualities. They are often judged during the study. And teachers do it not necessarily by asking questions.
- Prepare for doing homework in advance. It is worth refreshing the memory of algorithms, information structures and also going over the "weak" sides of JS for yourself.
- Don't forget concepts. Remembering the terminology will not be superfluous.
- Speak this or that solution aloud. A teacher wants to see how a student thinks. Although it may seem strange, speaking out aloud often helps not only to focus on the task but also to show oneself as a good developer/programmer. The right course of action can increase the chances of success.
- Give time for reflection. Before you take on homework, you need to understand it. A superficial concept can lead a student down the wrong path.
- Manual training. Use coding exercises manually, not with the usage of the computer. During doing homework, sometimes there are no special boards, no various prompts, no auto-formatting. The code written on paper will help you navigate better and not get confused.
Typical tasks and their analysis
A palindrome is a sequence of characters (sentence, word, phrase) that will read the same in both directions. Example: "civic," "radar," level," etc. This moment often slips in programming tasks and in JS homework as well.
A student is given a string. Write a function that:
- Will return true if the string is a palindrome;
- Otherwise, the result will be false;
- Do all this, taking into account spaces and available punctuation marks.
For example: if there is a string containing only the word cat, the value of the function should be false. And if you work with the racecar token. It should be true.
The work will be carried out in two stages:
- Convert the characters of the given string to lowercase. This will ensure that the utility accurately compares all character elements and not other components.
Line reverse. To do this, it is converted to an array through the split method of the String
library. After that, you need to flip the array using reverse. The final stage: the reverse
array is converted into a string through the
join()of the Array library.
The next task does not have a name as such, but it occurs quite often in homework. The student is asked to write a function that displays a number from 1 to n on the device display, where n is the number that this very function perceives as a parameter with conditions:
- fizz is shown on the screen instead of multiples of 3;
- fizzbuzz is indicated when the number is a multiple of both 3 and 5.
In other cases, a normal number will appear on the screen. This is an elementary task, but it can cause a lot of trouble even for experienced developers.
- module operator;
- via the remainder operator.
In the latter case, it is possible to understand --- if the remainder due to division is 0, this means that the first digit is a multiple of the second one.
Above there is the optimal code that allows you to solve the problem. Here the function will perform checks through conditional statements. The result is then presented to the user.
Special attention should be paid to the if...else statement and the order in which such elements are placed. The beginning is a double condition. The end is a situation in which no multiples are found. This will help to use all existing variations.
The practical assignments for students can be quite different. They are divided according to the level of difficulty. But often, teachers offer to solve simple but very tricky problems. Another example will be called an "Anagram." This is a word that contains all the letters of another lexeme and in the same amount. The only difference is in the order in which they are located.
It is required to write a function that will check for an anagram. You have to work directly with the strings - compare two of them. The case is not considered. Take into account only the characters. Punctuation marks and spaces are also not considered when resolving the corresponding question.
In order to perform such practical tasks, it is required to:
- Check each letter in the initial lines;
- Check the number of letters in each of the given strings.