Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translated UnarySystem experiment to html/css/js #430

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions css/bootstrap.min.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions js/bootstrap.min.js

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions src/lab/exp1/UnarySystem.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
html {
font-size: 2rem;
}

#num1, #num2 {
resize: none;
margin: 0.5rem auto;
text-align: center;
}

.main {
min-height: 65%;
display: flex;
width: 90%;
margin: auto;
align-items: center;
justify-content: center;
text-align: center;
}

.number-input {
margin: auto;
}

.result-container {
text-align: center;
font-size: 1.5rem;
word-wrap: break-word;
width: 90%;
margin: auto;
}



54 changes: 28 additions & 26 deletions src/lab/exp1/UnarySystem.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
<html>
<head>
<!-- Google Analytics Code starts here -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
<!-- Google Analytics Code starts here -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-42255654-1', 'virtual-labs.ac.in');
ga('send', 'pageview');
ga('create', 'UA-42255654-1', 'vlab.co.in');
ga('send', 'pageview');

</script>
<!-- Google Analytics Code ends here -->
</script>
<!-- Google Analytics Code ends here -->
<link rel="stylesheet" href="./UnarySystem.css">
<link rel="stylesheet" href="../../../css/bootstrap.min.css">
</head>
<body>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/
cabs/flash/swflash.cab#version=6,0,40,0"
width=100% height=100% id="intro">

<param name="movie" value="UnarySystem.swf" />

<param name="quality" value="high" />

<embed src="UnarySystem.swf" quality="high"
width=100% height=100% name="UnarySystem" align=""
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>

</object>
<div class="main">
<div class="w-50 form-group">
<label for="num1" class="control-label">Enter the first unary value</label>
<textarea id="num1" name="num1" cols="16" class="form-control" maxlength="32" required></textarea>
<button class="btn btn-primary" id="add_button" type="submit">ADD</button>
</div>
<div class="w-50 form-group">
<label for="num2" class="control-label">Enter the second unary value</label>
<textarea id="num2" name="num2" cols="16" class="form-control" maxlength="32" required></textarea>
<button class="btn btn-primary" id="mul_button">MUL</button>
</div>
</div>
<div class="result-container">
<p id="result">Enter numbers and press a button to operate.<br>Leave empty for 0.</p>
</div>
<script src="./UnarySystem.js"></script>
</body>
</html>
62 changes: 62 additions & 0 deletions src/lab/exp1/UnarySystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function restrictInput(e) {
this.value = this.value.replace(/[^1]+/, '');
}

function setupInput() {
let inputs = document.getElementsByTagName("textarea");

for(let i = 0; i < inputs.length; i++)
inputs[i].addEventListener('input', restrictInput);
}

function addNumbers() {
let num1 = document.getElementById("num1"),
num2 = document.getElementById("num2"),
result = document.getElementById("result");

num1 = num1.value;
num2 = num2.value;

let answer = num1 + num2;

if(!answer)
answer = "0";

result.textContent = `The sum of given numbers is ${ answer } [concatenation of both the numbers]`;
}

function mulNumbers() {
let num1 = document.getElementById("num1"),
num2 = document.getElementById("num2"),
result = document.getElementById("result");

num1 = num1.value.length;
num2 = num2.value.length;

let answerLength = num1 * num2,
answer = '';

for(let i = 0; i < answerLength; i++)
answer += '1';

if(!answer)
answer = "0";

result.textContent = `The product of given numbers is ${ answer } [1 repeated ${ num1 } * ${ num2 } times]`;
}

function setupHandlers() {
let addButton = document.getElementById("add_button"),
mulButton = document.getElementById("mul_button");

addButton.addEventListener('click', addNumbers);
mulButton.addEventListener('click', mulNumbers);
}

function main() {
setupInput();
setupHandlers();
}

main();