Commit a1e2c03a authored by Tapio Mäntysalo's avatar Tapio Mäntysalo
Browse files

Example works well, next remove button

parent a26d2bcb
"use strict";
/**
* Returns the greatest common divisor of a and b.
*
* @param {number} a a positive integer
* @param {number} b a positive integer
* @return {number} The greatest common divisor of a and b
*/
function gcd(a, b) {
// See https://www.geeksforgeeks.org/c-program-find-gcd-hcf-two-numbers/
if (b == 0) return a;
return gcd(b, a%b);
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<body>
<script>
function gcd(a, b) {
// See https://www.geeksforgeeks.org/c-program-find-gcd-hcf-two-numbers/
if (b == 0) return a;
return gcd(b, a%b);
}
let a = parseInt(prompt("Anna positiivinen kokonaisluku"));
let b = parseInt(prompt("Anna toinen pos. kokonaisluku"));
alert("Suurin yhteinen tekijä: " + gcd(a, b));
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<body>
<script src = "example.js"></script>
<script>
// We could include also the following lines in the js file but
// I decided to put only functions there
let a = parseInt(prompt("Anna positiivinen kokonaisluku"));
let b = parseInt(prompt("Anna toinen pos. kokonaisluku"));
alert("Suurin yhteinen tekijä: " + gcd(a, b));
</script>
</body>
</html>
\ No newline at end of file
......@@ -10,15 +10,11 @@
</head>
<body>
<!-- Example -->
<div class="container-md">
<div class="jumbotron">
<h1 class="display-4">Example</h1>
<p class="lead">This is the example provided.</p>
<!--<hr class="my-4">
<p>Test</p>
<a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a>
-->
<table>
<tbody>
<tr>
......@@ -48,19 +44,26 @@
</tr>
</tbody>
</table>
<button type="button" class="btn btn-primary btn-example" id="btn-example">Calculate</button>
<div>
<button type="button" class="btn btn-primary btn-example" id="btn-example">Calculate</button>
</div>
<hr>
<p id="card-example-result">
This is some text within a card body.
</p>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
<script src="new_example.js"></script>
</body>
......
$("#card-example-result").text("");
$('.input-example').val("1");
$(".input-example").keyup(function () {
let s = $(this).val();
s = s.replace(/\D/g,'');
s = s.replace(/\D/g, '');
$(this).val(s);
});
$("#btn-example").click(function () {
let a = $("#input-example-1").val();
let b = $("#input-example-2").val();
alert("Suurin yhteinen tekijä: " + gcd(a, b));
let gcd = getGreatestCommonDivisor(a, b);
$("#card-example-result").text(`Greatest common divisor = ${gcd}`);
});
function gcd(a, b) {
function getGreatestCommonDivisor(a, b) {
// See https://www.geeksforgeeks.org/c-program-find-gcd-hcf-two-numbers/
if (b == 0) return a;
return gcd(b, a % b);
return getGreatestCommonDivisor(b, a % b);
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment