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

example now works. now replace the alert w stg

parent b8dedaf1
......@@ -27,18 +27,20 @@
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Enter a positive integer</span>
</div>
<input type="number" class="form-control" placeholder="1" aria-label="positive-integer-1"
<input type="text" class="form-control input-example" placeholder="1"
id="input-example-1" aria-label="positive-integer-1"
aria-describedby="basic-addon1">
</div>
</td>
<td>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Enter another positive
<span class="input-group-text" id="basic-addon2">Enter another positive
integer</span>
</div>
<input type="text" class="form-control" placeholder="2" aria-label="positive-integer-2"
aria-describedby="basic-addon1">
<input type="number" class="form-control input-example" placeholder="2"
id="input-example-2" aria-label="positive-integer-2"
aria-describedby="basic-addon2">
</div>
</td>
<td>
......@@ -46,20 +48,10 @@
</tr>
</tbody>
</table>
<button type="button" class="btn btn-primary">Laske</button>
<button type="button" class="btn btn-primary btn-example" id="btn-example">Calculate</button>
</div>
</div>
<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>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
......@@ -69,6 +61,7 @@
<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>
</html>
\ No newline at end of file
$(".input-example").keyup(function () {
let s = $(this).val();
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));
});
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
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