In line 1 of the program, we inform the browser that our document is written in the HTML language (specifically, this is the header characteristic of HTML 5). Line 2 contains the <html> tag, which starts the HTML code. Line 3 begins the <body> section of our document, containing the elements that are meant to appear on the page. In our example, the <body> section contains only a script written in JavaScript that implements the linear equation solving algorithm (Note: The Polish text says "linear equation" here, although the function defined later is "factorial"). The start of the script is indicated by the <script> tag in line 4—we can treat this as the START block (1) of our algorithm. The content of the script is contained in lines 6 through 14.
In line 6, we declare a single-argument function named factorial (factorial). The function body—the set of instructions executed by the program when this function is called—is contained between the curly brace { at the end of line 6 and } on line 11.
In line 7, we check if n is greater than 1—block (3) of the algorithm. If so, then in line 8, we set the function's result as n multiplied by the value of the factorial function (the same factorial function we are currently defining) for n minus 1 (4). At this point, the factorial function calls itself. Such a function is called a recursive function. If n is not greater than 1, then in line 10, we set the function's result equal to 1 (the condition for ending the recursion)—block (5).
In line 13, using the keyword var, we declare the variable n; simultaneously, the assignment operator ("=") initializes this variable with a value entered by the user using the prompt() instruction—block (2) of the algorithm. prompt—a standard JavaScript function—displays a pop-up text input window on the screen. The first argument of the function specifies the text displayed as the prompt, and the second is the default value entered into the edit field. In our case, we display the text "n:" as the prompt and do not suggest any default text to the user (the second argument is an empty string ""). The prompt() function returns the text entered by the user into the edit field and then confirmed with the OK button.
In line 14, using the alert() function, we print the value of the variable n, the text "!=", and finally the result of calling the factorial(n) function—block (6) of the algorithm.
The </script> tag in line 16 ends the program's execution (the algorithm's STOP block (9)).
Finally, in lines 17 and 18, we close the </body> and </html> sections.
