Skip to content

Instantly share code, notes, and snippets.

@lenka21
Created May 7, 2015 07:14
Show Gist options
  • Save lenka21/db6eb191cc6fd7a704ea to your computer and use it in GitHub Desktop.
Save lenka21/db6eb191cc6fd7a704ea to your computer and use it in GitHub Desktop.
silnia
<html>
<head lang="pl">
<meta charset="UTF-8">
<title>silnia</title>
<script src="main.js"></script>
</head>
<body>
<h1>Podaj liczbe</h1>
<input id="n">
<button onclick="licz()">Licz silnie</button>
<h2 id="view"></h2>
</body>
</html>
function silnia(){
var n = document.getElementById("n").value;
var result = 1;
if (n < 0) {
result = "n musi byc wieksze lub rowne 0";
} else {
for (var i = 1; i <= n; i++){
result = result*i;
}
}
document.getElementById("view").innerHTML = result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment