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

Dom homework #45

Open
wants to merge 6 commits 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
8 changes: 8 additions & 0 deletions Maryam-Marjoori/homework-9/10-homework-stocks/stocks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<script src="stocks.js"></script>
</head>
<body>

</body>
</html>
65 changes: 65 additions & 0 deletions Maryam-Marjoori/homework-9/10-homework-stocks/stocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Create a `Stock` constructor that has the following attributes:
* symbol - (a string)
// Every stock listed on a stock exchange has a symbol, which is usually between
// one and four capital letters, such as V or AAPL.
* shares - (a number)
// Stocks are sold in shares, which can be whole numbers or decimal amounts.
* exchange - (a string equal to NYSE)
// Stocks are sold on stock exchanges, such as the New York Stock Exchange (NYSE) or the NASDAQ.
// The NYSE is the largest in the U.S., so we are setting this as a default value for our constructor.

And the following methods:
* buyShares(number) - adds the number of shares purchased (a number) to the value of the shares property
* sellShares(number) - subtracts the number of shares sold (a number) from the value of the shares property
* calcValue(price) - multiplies the value of the shares property by the price (a number) and returns the result

## Goal

Make sure to use the Stock prototype so that you're not creating multiple copies of the functions for your stocks.

## Testing

Create a stock using the name "visa" and the values "V" for symbol and 100 for shares.
Use the buyShares() method to buy 50 shares.
Use the sellShares() method to sell 75 shares.
Use the calcValue() method to calculate the value at a price of 50.35.
Create a stock using the name "apple" and the values "AAPL" for symbol and 200 for shares. Specify
the value "NASDAQ" for exchange. Check the values of the exchange property for apple and for visa
and verify that the value for apple is the one you just set, while the value for visa remains "NYSE".

## Bonuses

1. Ensure that the total number of shares is never less than zero.
2. Ensure that calculated values are always rounded to the nearest cent.
*/

function Stock (symbol,shares){
this.symbol = symbol,
this.shares = shares,
this.exchange = "NYSE"
}

Stock.prototype.buyShares = function(sharedPurchased){
if (0 > sharedPurchased){
console.log("You can't but negative number of shares.")
}
else {
return "Total shares you have is equal to: " + (this.shares + sharedPurchased);
}
};
Stock.prototype.sellShares = function(sharedSold){
if (sharedSold > this.shares){
console.log( "You can't sale " + sharedSold + " shares becasue it's more than what you currently have.");
}
else {
return "Your remaining shares are equal to: " + (this.shares - sharedSold);
}
};
Stock.prototype.calcValue = function(currentPrice){
return "The price is $" + Math.round(this.shares * currentPrice);
};

var visa = new Stock("V",100);
var apple = new Stock("AAPL",200);
apple.exchange = "NASDAQ";
2 changes: 1 addition & 1 deletion Maryam-Marjoori/homework_3/3-dice-lab/approach-2/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var diceLeft = ["img/1.png" , "img/2.png" ,"img/3.png", "img/4.png" , "img/5.png
var diceRight = ["img/1.png" , "img/2.png" ,"img/3.png", "img/4.png" , "img/5.png" , "img/6.png"];


//2 Insetad of calling them array elements by their fixed IDs (ex:diceLeft[4]), for both arrays I need to call array elements by a variable which randomly changes from 0 to 5
//2 Insetad of calling the array elements by their fixed IDs (ex:diceLeft[4]), for both arrays I need to call array elements by a variable which randomly changes from 0 to 5

//var random1 = Math.floor(Math.random() * 6 );
//var random2 = Math.floor(Math.random() * 6 );
Expand Down
8 changes: 8 additions & 0 deletions Maryam-Marjoori/homework_4/1-json-exercise/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<script src="app.js"></script>
</head>
<body>

</body>
</html>
136 changes: 136 additions & 0 deletions Maryam-Marjoori/homework_4/1-json-exercise/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@

'use strict';

// JSON is a subset of the object literal notation of JavaScript; we use JSON to transfer data between programs.
// ---- RULES ----
// Property names must be double-quoted strings; trailing commas are forbidden.
// Leading zeroes are prohibited; a decimal point must be followed by at least one digit.
// Most characters are allowed in strings, except certain control characters.
// Strings must be double quoted.
// No comments!
//
// More on JSON here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON

// Although the following statement isn't technically JSON (since it's actual JavaScript code)
// the object that's being saved with the variable name `notActuallyJSON` is written in valid JSON syntax.
var notActuallyJSON = {
"someKey": "someValue",
"innerArray": [
"alpha",
"beta",
"gamma",
"delta"
]
};

// [ Step 1 ] Use JSONLint to determine if something is valid JSON.
// Copy the entire object above (including the opening and closing braces {...}, but NOT 'var notActuallyJSON =' or the trailing semicolon).
// Then go to http://jsonlint.com/ and paste it into the validator. Does it pass the test of being valid JSON?


// [ Step 2 ] The following statement is valid JavaScript, but the object it creates is not written in valid JSON syntax.
// Use JSONLint to validate the object in the following line; then, edit the object so it passes the validator.
var eddie = {name:"Eddie Vedder", age:49};
// JSON:
/*
{
"name": "Eddie Vedder",
"age": 49
}
*/


// [ Step 3 ] Turn the `grungeAlbums` JavaScript object below into a JSON string, and store it in the variable `grungeAlbumsJSON`.
// Then, convert `grungeAlbumsJSON` back into a JavaScript object, and compare it to the original `grungeAlbums`. Are they the same?

// Hint: To turn a JS Object into JSON, use the .stringify method ( JSON.stringify(someObject) )
// (See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)

var grungeAlbums = {
"albums":[
{
"name": "Bleach",
"artist": "Nirvana",
"unitsSold": 1700000
},
{
"name": "Nevermind",
"artist": "Nirvana",
"unitsSold": 30000000
},
{
"name": "In Utero",
"artist": "Nirvana",
"unitsSold": 15000000
},
{
"name": "Ten",
"artist": "Pearl Jam",
"unitsSold": 10000000
},
{
"name": "Vs",
"artist": "Pearl Jam",
"unitsSold": 6100000
},
{
"name": "Vitalogy",
"artist": "Pearl Jam",
"unitsSold": 4770000
}
]
};

var grungeAlbumsJSON = JSON.stringify(grungeAlbums);
var grungeAlbumsObject = JSON.parse(grungeAlbumsJSON);

// [ Step 4 ] Take `grungeAlbumsJSON` and convert it back into a JavaScript object.
// Then, for each album in the list, do a console log printing out the album name, artist, and units sold.
// Each album should be formatted as follows:

// Album: Album name
// Artist: Artist name
// Units sold: 31234

// *************************************************Solution *****************************************************
// 1- The "grungeAlbumsObject" Object has only one Propperty which is album. Album by itself is an array of index = 5 .
// Each index by itself is an object with three propperties.Name ,Artist and Unitsold
// 2- Since album itself is an array I use for loop to loop through it's index values.
// 3- I used

for (var i = 0; i < grungeAlbums.albums.length ; i++){
document.write(" <br> Name :" + grungeAlbums.albums[i].name + " <br> Artist: " + grungeAlbums.albums[i].artist + "<br> UnitSold :" + grungeAlbums.albums[i].unitsSold + "<br>");
}

// Solving this with a nested For in loop, since each index is an object with three propperties:
// for (var i = 0; i < grungeAlbums.albums.length ; i++){
// for (var prop2 in grungeAlbums.albums[i]){
// console.log( prop2 + ": " + grungeAlbums.albums[i][prop2]+ "\n");
// }
// }


// Hint: To turn a JSON string into a JS Object, use the .parse method ( JSON.parse('some string') )
// (See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)


// [ Step 5 ] Create a custom JSON string using the JSON validator from Step 1.
// Convert it back to a JavaScript object, change it, and then convert it back to JSON again. Compare it to your original - how has it changed?
var myInformation = {
"firstName" : "Maryam",
"lastName" : "Kazerooni",
"favFruits" : ["Peach", "Pluat" , "Watermelon", "Strawberry"],
"siblings" : [
{ "brother": "Yousef",
"age": 30,
"favColor" : ["red","green","gary"]
},
{
"sister": "Yasi",
"age" : 32,
"favColor" : ["black","purple","pink"]
}
]
}


119 changes: 119 additions & 0 deletions Maryam-Marjoori/homework_4/2-object-homework/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/////////////////////////////////////////////////////////////

///////////////////////// Challenge /////////////////////////

/////////////////////////////////////////////////////////////

// Write your answers inside this file, at the places where it's indicated by the comments.


// 1. Suppose that we wanted to create a browser-based calendar program for keeping track of things. In comments, list at least three reasonable abstractions that you might use to build this program; for each abstraction, list out at least two properties and behaviors that it would make sense for that abstraction to have. Below is an example - please write your answer in the same format.
// 'Car'
// Description: Our app manages car sales.
// Every 'car' has
// - a make
// - a model
// - a year
// Every 'car' can
// - drive
// - brake
// - park

// Answer Starts Here

// "Browser-based calendar"
// Description: Our browser-based calendar keeps track of things.
// Every 'browser-based calendar' has
// - a calendar
// - visual interface to display ,Year, month, day
// - visual interface to display hour , minute , second
// Every 'calendar' can
// - Add events
// - Remove events
// - Edit exsiting events

// - a browser
// - name
// - version
// - plugin
// - resolution
// - settings
// Every browser can
// - change size
// - scroll
// - enable/doiable plugins

// - a device which the browser is viewd from
// - Type
// - brand
// - Model
// - settings
// Every device can
// - be turned on or off
// - cause the browser to load a different set of style sheets

// - a user who is using the calendar
// - Full Name
// - User name
// - Password
// - preferrences
// Every user can
// - create an account for the calendar
// - Share calandar with other


// Answer Ends Here


// 2. Create an Object literal that lines up with the following description. Store it in the variable 'pet_owner', below. Be sure to give it reasonable values for each of its properties.

// 'Owner'
// Description: We are making an app for a veterinary clinic - it manages pets' vaccinations.
// Every 'owner' has:
// - a name
// - an address

var pet_owner;

// Answer Starts Here

var pet_owner= {
ownerName : " ",
ownerAddress : " "
};

// Answer Ends Here


// 3. Create an Object literal that lines up with the following description. Store it in the variable `some_pet`, below.

// Pet
// Description: We are making an app for a veterinary clinic - it manages pets' vaccinations.
// Every 'pet' has:
// - a name
// - a species
// - a breed
// - a noise that it can make (e.g. 'bark', 'meow', etc.)
// Every pet can:
// - make noise (each pet makes its own unique noise, as specified by `noise`.

var some_pet;

// Answer Starts Here

var some_pet = {
name: " ",
species: " ",
breed: " ",
noise: [],
makeNoise : function(noise){
}
};

// Answer Ends Here

/////////////////////////////////////////////////////////////

// You're done!

/////////////////////////////////////////////////////////////
12 changes: 12 additions & 0 deletions Maryam-Marjoori/homework_4/2-object-homework/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Output for pet objects challenge</h1>

<script src="app.js" type="text/javascript" charset="utf-8" async defer></script>

</body>
</html>
8 changes: 8 additions & 0 deletions Maryam-Marjoori/homework_4/3-json-homework/json-hw.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<script src="json-hw.js"></script>
</head>
<body>

</body>
</html>
63 changes: 63 additions & 0 deletions Maryam-Marjoori/homework_4/3-json-homework/json-hw.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions Maryam-Marjoori/homework_5/1-js_dom_exercise/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>A Few of My Favorite Things</title>
</head>
<body>
<h1>Favorite Things</h1>
<ul id="fav-list">
<li class="fav-thing">Dog bites</li>
<li class="fav-thing">Bee Stings</li>
<li class="fav-thing">Feeling Bad</li>
</ul>

<form>
<input id="new-thing">
<input id="new-thing-button" type="submit" value="Create new thing">
</form>
<script src="main.js" type="text/javascript"></script>
</body>
</html>
Loading