Skip to content
Merged
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
43 changes: 37 additions & 6 deletions bike-shop/src/stage2-constructors.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
function Bike() {
// your code here
function Bike(name, price) {
alert(new.target);
this.name = name
this.price = price
this.rings = [3, 7]
this.brakes = {
back : true,
front : true
},
this.tires = [new Tire, new Tire]
this.frame = new Frame
}

function Frame() {
// your code here
function Frame(color, size, style) {
this.color = color ? color : "black"
this.size = size ? size : 55
this.style = style ? style : "street"
}

function Tire() {
// your code here
function Tire(diameter, type) {
this.diameter = diameter ? diameter : 22
this.type = type ? type : 'street'
this.rings = [2, 5]
}


module.exports = {
Bike: Bike,
Frame: Frame,
Tire: Tire
}




const myFrame = new Frame()
//myFrame.color = "black"
//myFrame.size = 55
//myFrame.style = "street"

const myBike = new Bike()
//myBike.name = ""
//myBike.price = ""
//myBike.tires = ["front", "back"]

const myTire = new Tire()
//myTire.diameter = ""
//myTire.type = ""
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<title></title>
</head>
<body>
<script src="jsinfo/createNewAccumlator.js" charset="UTF-8"></script>
<script src="bike-shop/src/stage2-constructors.js" charset="UTF-8"></script>
</body>
</html>
11 changes: 4 additions & 7 deletions jsinfo/createNewAccumlator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ In other words, the value property is the sum of all user-entered values with th


function Accumulator(startingValue) {
//holds the startingValue to be minipulated
this.value = startingValue;

this.read = function () {
this.value1 = parseFloat(prompt("what is the first value"));
startingValue += this.value1;
console.log(startingValue);
//adds the prompted amount to the value at the moment
this.value += parseFloat(prompt("what is the first value"));
};

this.value = function (startingValue) {
return Accumulator.startingValue
}
}


Expand Down
40 changes: 40 additions & 0 deletions jsinfo/extendableCalculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//Create a calculator that can take a string and return the value
function Calculator() {

let methods = {
"+" : function(value1, value2){
return parseFloat(value1) + parseFloat(value2)
},
//arrow function
"-" : (value1, value2) => parseFloat(value1) - parseFloat(value2),
}

this.calculate = function (str) {

let strSplit = str.split(" ");
var value1 = strSplit[0];
var value2 = strSplit[2];
var operator = strSplit[1];

return methods[operator](value1, value2)
};

this.addOperator =function (name, func){
methods[name] = func;
}
}

let calc = new Calculator;

alert( calc.calculate("3 + 7") ); // 10

let newCalc = new Calculator

newCalc.addOperator("*", (a, b) => a * b);
newCalc.addOperator("/", (a, b) => a / b);
newCalc.addOperator("**", (a, b) => a ** b)
newCalc.addOperator("pie", (a,b) => "I have " + a + " pies cut into " + b + " slices each")
alert(newCalc.calculate("2 * 3")); //6
alert(newCalc.calculate("2 ** 3")); //8
alert(newCalc.calculate("6 / 2")); //3
alert(newCalc.calculate("7 pie 4"));
Empty file added jsinfo/searthingAlgo.js
Empty file.