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

Task-1 works now

parent 2e2a4c94
$(".input-example").keyup(function () {
// Ensure only number are entered
let s = $(this).val();
s = s.replace(/\D/g, '');
// });
// $("#btn-example").click(function () {
// Calculate and display the result
let a = +$("#input-example-1").val();
let b = +$("#input-example-2").val();
let gcd = getGreatestCommonDivisor(a, b);
......@@ -10,6 +10,33 @@
<!-- Task 1 -->
<div class="container-md">
<div class="jumbotron">
<h1 class="display-4">Task 1</h1>
<p class="lead">Conditional statements</p>
<hr class="my-4">
<p> Write a program that asks the user’s age. If the age is 1-122 years the program welcomes the user. If
the age is 123-150 years, the program notes that we have a new age record. If the age is less than 1 or
more than 150 years, the program states that the user seems to be lying. For user interaction you can
use those mentioned in alert and prompt. The latter one can be used as follows: let age
= parseInt(prompt("What is your age in years?")); You may assume that the user inputs an integer.
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">What is your age in years?</span>
<input type="text" class="form-control input-task-1" placeholder="" id="input-task-1"
aria-label="positive-integer-1" aria-describedby="basic-addon1">
<button type="button" class="btn btn-primary" id="btn-task-1">Answer</button>
<p id="card-task-1-result"></p>
<!-- Example -->
<div class="container-md">
<div class="jumbotron">
......@@ -57,7 +84,8 @@
<script src="new_example.js"></script>
<script src="task1.js"></script>
<script src="example.js"></script>
\ No newline at end of file
// Ensure that only numbers are entered
$("#input-task-1").keyup(function () {
let s = $(this).val();
s = s.replace(/\D/g, '');
// Show the result
$("#btn-task-1").click(function () {
let age = +$("#input-task-1").val();
let statement = getStatementForAge(age);
function getStatementForAge(age) {
if (age >= 1 && age <= 122) {
return "Welcome!";
else if (age >= 123 && age <= 150) {
return "We have a new age record!";
else {
return "You seem to be lying.";
\ No newline at end of file
Supports Markdown
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