Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
minimum, recursion, bean counting and tip calculator
  • Loading branch information
met18001 committed Feb 23, 2020
1 parent 2ae7292 commit 708762f
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 0 deletions.
32 changes: 32 additions & 0 deletions week-5/bean_counting.html
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bean Counting</title>
</head>
<body>

<script>

function countBs(string) {
return countChar(string, 'B');
}

function countChar(string, chr) {
var counter = 0
for (var i = 0; i < string.length; i++) {
if (string.charAt(i) === chr) {counter++;}
}
return counter;
}

console.log(countBs("BBC"));
// → 2
console.log(countChar("kakkerlak", "k"));
// → 4


</script>
</body>
</html>
28 changes: 28 additions & 0 deletions week-5/minimum.html
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>

const min = function(arg1, arg2){
if (arg1 < arg2)
return arg1;
else
return arg2;
}


console.log(min(0, 10));
// → 0
console.log(min(0, -10));
// → -10



</script>
</body>
</html>
31 changes: 31 additions & 0 deletions week-5/recursion.html
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Recursion</title>
</head>
<body>
<script>
var isEven = function(num) {
num = Math.abs(num);
if (num === 0)
return true;
else if (num === 1)
return false;
else
return isEven(num - 2);
};

console.log(isEven(50));
// → true
console.log(isEven(75));
// → false
console.log(isEven(-1));
// → ??



</script>
</body>
</html>
27 changes: 27 additions & 0 deletions week-5/tip-calculator-master/.gitignore
@@ -0,0 +1,27 @@
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
18 changes: 18 additions & 0 deletions week-5/tip-calculator-master/README.md
@@ -0,0 +1,18 @@
# Tip Calculator
An exercise in JavaScript function definitions and return values. Course: DMD 3475.

## Introduction
Our tip calculator application is almost complete. Our function named `updateValues()` will fetch the values that were input by the user.

At that point, the values are passed as arguments to two functions named `calculateTipPerPerson()` and `calculateTotalPerPerson()`. The values that are returned by each function are used to update the DOM.

## Instructions

1. Define both required functions: `calculateTipPerPerson()` and `calculateTotalPerPerson()`.
2. Each function should accept the 3 arguments being passed to them within the `updateValues()` function.
3. Using those values, calculate and return the appropriate answer.
4. Extra credit: Properly round the dollars and cents that are returned by your functions.

## Helpful Information
* Search Google for "Tip Calculator" to see the desired functionality for this application.
* The `calculateTotalPerPerson()` function should return a value that includes the tip.
28 changes: 28 additions & 0 deletions week-5/tip-calculator-master/css/main.css
@@ -0,0 +1,28 @@
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}

.card {
width: 400px;
max-width: 100%;
}

.card-image img {
height: 100px;
object-fit: cover;
object-position: center;
}

.card-content .row {
margin: 0;
}


.card .card-image .card-title {
font-weight: bold;
text-shadow: 2px 2px 3px black;
padding-bottom: 12px;
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions week-5/tip-calculator-master/index.html
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tip Calculator</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link rel="stylesheet" href="css/main.css">
</head>
<body class="blue darken-3">


<div class="card z-depth-2">
<div class="card-image">
<img src="images/claudia-crespo-ewOrvEa87j4-unsplash.jpg">
<span class="card-title">Tip Calculator</span>
</div>
<div class="card-content">
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field">
<i class="material-icons prefix">attach_money</i>
<input type="number" id="total" value="100.00" min="1"></input>
<label for="total">Bill Total</label>
</div>
<div class="input-field">
<i class="material-icons prefix">pie_chart</i>
<input type="number" id="tip" value="15" min="0"></input>
<label for="tip">Tip Percentage</label>
</div>
<div class="input-field">
<i class="material-icons prefix">group_add</i>
<input type="number" id="people" value="1" min="1"></input>
<label for="people">Number of People</label>
</div>
</div>
</form>
</div>
</div>
<div class="card-action">
<div class="row">
<div class="col s6">
Tip (per person): $<span class="tipOutput"></span>
</div>
<div class="col s6">
Total (per person): $<span class="totalOutput"></span>
</div>
</div>
</div>
</div>


<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>
74 changes: 74 additions & 0 deletions week-5/tip-calculator-master/js/script.js
@@ -0,0 +1,74 @@
/**
* Get references to each of the form inputs
*/
let total = document.querySelector('#total');
let tip = document.querySelector('#tip');
let people = document.querySelector('#people');

/**
* Whenever the fields are updated, we call
* the updateValues function.
*/
total.addEventListener('change', updateValues);
total.addEventListener('keyup', updateValues);
tip.addEventListener('change', updateValues);
tip.addEventListener('keyup', updateValues);
people.addEventListener('change', updateValues);
people.addEventListener('keyup', updateValues);

/**
* We will need references for the span tags
* that we will use to output our results.
*/
let tipOutput = document.querySelector(".tipOutput");
let totalOutput = document.querySelector(".totalOutput");

/**
* This function is run every time an input is changed
* by a user.
*/
function updateValues(event){

// Get the latest values from our form inputs
let totalValue = total.value;
let tipValue = tip.value;
let peopleValue = people.value;

// Update the values on the screen
tipOutput.innerText = calculateTipPerPerson(totalValue, tipValue, peopleValue);
totalOutput.innerText = calculateTotalPerPerson(totalValue, tipValue, peopleValue);
}

/**
* Your code goes down here ...
* @todo Write functions for calculateTipPerPerson() and calculateTotalPerPerson()
*/

function calculateTipPerPerson(totalValue, tipValue, peopleValue){

var total = (totalValue * (tipValue * .01) )/peopleValue;
console.log(total);
total = Math.round(total * 100) / 100;
return total;

}



function calculateTotalPerPerson(totalValue, tipValue, peopleValue){
var total = totalValue + (totalValue * (tipValue * .01) )/peopleValue;
console.log(total);
total = Math.round(total * 100) / 100;
return total;

}

// var newTotal = calculateTipPerPerson(total) + (totalValue * (tipValue * .01) )/peopleValue;
// console.log(newTotal);
// total = Math.round(newTotal * 100) / 100;
// return newTotal;





0 comments on commit 708762f

Please sign in to comment.