JavaScript: How we check your solutions
Our website automatically checks your solutions. How does it work?
In the simplest case, the check runs your code and compares the screen output with the expected result. For example, if the task says: "Print the number 10 to the screen," then your JavaScript code might look like this:
console.log(10);The check will run this code and make sure that 10 actually appears on the screen. If the output matches the expected one, the solution is accepted. Otherwise, you will see an error:
● test
expect(received).toBe(expected) // Object.is equality
Expected value to be:
"10"
Received:
"9"Expected is the expected result, and Received is the one your code returned.
In the following, more complex lessons, you will write functions. They take data and return a result. In such tasks, the check works a little differently: it calls your function with different arguments and knows in advance which answer should be obtained in each case.
For example, if you need to write a function that adds two numbers, the check will pass it different pairs of numbers and compare the result with the correct sum. If the answers match in all cases, the solution is considered correct.
This approach is called testing, and it is used in real-world development. Tests help verify whether a program works correctly and quickly catch an error after changes.
That is exactly why our website says "Tests passed" when you have solved the task correctly.
My mistake or not?
Sometimes during the solution process it will seem that you did everything correctly, but the check does not accept the solution. This happens extremely rarely. Tests run automatically after every change, so a broken check usually does not make it to the website.
In the vast majority of such cases, the error is contained in the solution code. It can be very subtle: instead of an English letter you accidentally typed a Russian one, instead of uppercase you used lowercase, or you forgot to print a comma. There are also more complex situations. For example, the solution works for one set of input data, but does not work for another.
So always carefully read the task statement and the test output. There is almost certainly an indication of the error there.
If you are sure that the problem is in the task or you have found an inaccuracy, write to our community, in the 'Feedback' channel.
In addition to the exercises on the website, it will be extremely useful to experiment with code in the browser console. In any situation when you do not fully understand something or want to try different options, feel free to open the console and type code there.
Instructions
There are 10 apples left on the shelf in the store. Write a program that prints this number to the screen.
Then try printing a different number and see what the checking system shows. This will help you learn to read test error messages.
Tips
If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:
- Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
Tests are designed so that they test the solution in different ways and against different data. Often the solution works with one kind of input data but doesn't work with others. Check the «Tests» tab to figure this out, you can find hints at the error output.
It's fine. 🙆 One task in programming can be solved in many different ways. If your code passed all tests, it complies with the task conditions.
In some rare cases, the solution may be adjusted to the tests, but this can be seen immediately.
It's hard to make educational materials that will suit everyone. We do our best but there is always something to improve. If you see a material that is not clear to you, describe the problem in “Discussions”. It will be great if you'll write unclear points in the question form. Usually, we need a few days for corrections.
By the way, you can participate in courses improvement. There is a link below to the lessons course code which you can edit right in your browser.
Создавать обучающие материалы, понятные для всех без исключения, довольно сложно. Мы очень стараемся, но всегда есть что улучшать. Если вы встретили материал, который вам непонятен, опишите проблему в обратной связи нашего сообщества
Your exercise will be checked with these tests:
// @ts-check
import { expect, test, vi } from 'vitest';
test('hello world', async () => {
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
await import('./index.js');
const firstArg = consoleLogSpy.mock.calls.join('\n');
expect(firstArg).toBe('10');
});Teacher's solution will be available in:
20:00
