Created
April 17, 2020 04:47
-
-
Save jadeallencook/48d92954ab3e685c0ede2ba18248acf8 to your computer and use it in GitHub Desktop.
Paste into your browser to generate a stock report.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let investments = 0; | |
let loses = 0; | |
let gains = 0; | |
let down = []; | |
let up = []; | |
document | |
.querySelectorAll('span.theme-closed-down') | |
.forEach(elem => { | |
investments++; | |
loses++; | |
down.push(elem.innerText); | |
}); | |
document | |
.querySelectorAll('span.theme-closed-up') | |
.forEach(elem => { | |
investments++; | |
gains++; | |
up.push(elem.innerText); | |
}); | |
down = down | |
.map(num => Number( | |
num | |
.replace('-$', '') | |
.replace(',', '') | |
)).reduce((num, total) => num + total, 0); | |
up = up | |
.map(num => Number( | |
num | |
.replace('+$', '') | |
.replace(',', '') | |
)).reduce((num, total) => num + total, 0); | |
console.log( | |
`You've made ${investments} investments\n`, | |
`Loses(${loses}): -$${Math.round(down)}\n`, | |
`Gains(${gains}): -$${Math.round(up)}` | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment