This commit is contained in:
Miloslav Ciz 2024-08-05 22:39:28 +02:00
parent 275c83d379
commit 793eff5870
19 changed files with 2117 additions and 1835 deletions

View file

@ -16,6 +16,53 @@ In the past JavaScript was only a **[client](client.md) side** scripting languag
TODO: some more shit
## Examples
Below is our standardized [divisor tree](divisor_tree.md) program written in browser JavaScript:
```
<html> <head> <script>
// recursive function, returns divisor tree of x as a string
function divisorTreeStr(x)
{
let a = -1, b = -1;
let s = "";
for (let i = 2; i <= x / 2; i++) // find closest divisors
if (x % i == 0)
{
a = i;
b = x / i;
if (b <= a)
break;
}
s += "("
s += a > 1 ?
divisorTreeStr(a) + " " + x + " " + divisorTreeStr(b) : x;
return s + ")";
}
function main()
{
while (true) // main loop, read numbers from the user
{
let x = parseInt(prompt("enter a number:"));
if (isNaN(x) || x < 0 || x >= 1000)
break;
console.log(divisorTreeStr(x));
}
}
</script> </head> <body onload="main()"> </body> </html>
```
## JavaScript Fun
Here let be recorded funny code in this glorious language.