Javascript tipiniai uždaviniai

Šiame įraše kelsiu įvairius tipinius uždavinius, kurie bus sprendžiami su JavaScript.

Faktorialai

Faktorialų skaičiavimas su paaiškinimais.

Faktorialų pvz.


4! = 4 * 3 * 2 * 1 = 24
5! = 5 * 4 * 3 * 2 * 1 = 120

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
var solution = 1;
for (var x = 5; x > 0; x = x - 1) {
console.log(solution + " " + x);
solution = solution * x;
console.log("Suma: " + solution / x + " * " + x + " = "+ solution )
}
console.log("Sprendimas: " + solution)
var solution = 1; for (var x = 5; x > 0; x = x - 1) { console.log(solution + " " + x); solution = solution * x; console.log("Suma: " + solution / x + " * " + x + " = "+ solution ) } console.log("Sprendimas: " + solution)
var solution = 1;

for (var x = 5; x > 0; x = x - 1) {
      console.log(solution + " " + x);
      solution = solution * x;
      console.log("Suma: " + solution / x + " * " + x + " = "+ solution )
}
console.log("Sprendimas: " + solution)

 

Add a Comment

Your email address will not be published. Required fields are marked *

Buy Me A Coffee
Thank you for visiting. You can now buy me a coffee!