https://github.com/andrewjbateman/javascript-add-times
:clipboard: Add video times to give a total time. Wes Bos Javascript30 Youtube Tutorial 18.
https://github.com/andrewjbateman/javascript-add-times
css html5 javascript30 tutorial-exercises
Last synced: 5 months ago
JSON representation
:clipboard: Add video times to give a total time. Wes Bos Javascript30 Youtube Tutorial 18.
- Host: GitHub
- URL: https://github.com/andrewjbateman/javascript-add-times
- Owner: AndrewJBateman
- Created: 2018-12-06T07:01:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-04-10T09:59:33.000Z (almost 4 years ago)
- Last Synced: 2024-12-27T02:45:04.468Z (about 1 year ago)
- Topics: css, html5, javascript30, tutorial-exercises
- Language: HTML
- Homepage:
- Size: 247 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# :zap: Javascript Local Storage
* Wes Bos Youtube Javascript30 tutorial: [How JavaScript's Array Reduce Works - #JavaScript30 18/30](https://www.youtube.com/watch?v=SadWPo2KZWg&list=PLu8EoSxDXHP6CGK4YVJhL_VWetA865GOH&index=18).
* **Note:** to open web links in a new window use: _ctrl+click on link_




## :page_facing_up: Table of contents
* [:zap: Javascript Add Times](#zap-javascript-add-times)
* [:page_facing_up: Table of contents](#page_facing_up-table-of-contents)
* [:books: General info](#books-general-info)
* [:camera: Screenshots](#camera-screenshots)
* [:signal_strength: Technologies](#signal_strength-technologies)
* [:floppy_disk: Setup](#floppy_disk-setup)
* [:wrench: Testing](#wrench-testing)
* [:computer: Code Examples](#computer-code-examples)
* [:cool: Features](#cool-features)
* [:clipboard: Status & To-Do List](#clipboard-status--to-do-list)
* [:clap: Inspiration](#clap-inspiration)
* [:file_folder: License](#file_folder-license)
* [:envelope: Contact](#envelope-contact)
## :books: General info
* Tutorial Code to understand how to sum time strings using the reduce function.
## :camera: Screenshots
.
## :signal_strength: Technologies
* [Javascript ECMA-262 ECMAScript 2021](http://www.ecma-international.org/publications/standards/Ecma-262.htm)
## :floppy_disk: Setup
* Open index.html in browser. If any code is changed the browser needs to be refreshed.
## :computer: Code Examples
* Use map, split and reduce functions to obtain total seconds then convert to hours, moins and seconds.
```javascript
// turn secs:mins nodes into an array of strings then split into mins secs
// then use parsefloat function to return an array of numbers.
// then convert to a total seconds value
// then use reduce function to produce a total in seconds.
const seconds = timeNodes
.map(node => node.dataset.time)
.map(timeCode => {
const [mins, secs] = timeCode.split(':').map(parseFloat);
return (mins * 60) + secs;
})
.reduce((total, vidSeconds) => total + vidSeconds)
let secondsLeft = seconds;
const hours = Math.floor(secondsLeft / 3600);
secondsLeft = secondsLeft % 3600; // leftover from minutes is seconds
const mins = Math.floor(secondsLeft / 60);
secondsLeft = secondsLeft % 60;
```
## :cool: Features
* Gives total video play time in hours, mins & secs.
## :clipboard: Status & To-Do List
* Status: Working.
* To-Do: This code can be enhanced with HTML to show the time values from the javascript calculations.
## :clap: Inspiration
* Wes Bos Youtube Javascript30 tutorial [How JavaScript's Array Reduce Works - #JavaScript30 18/30](https://www.youtube.com/watch?v=SadWPo2KZWg&list=PLu8EoSxDXHP6CGK4YVJhL_VWetA865GOH&index=18)
## :file_folder: License
* N/A
## :envelope: Contact
* Repo created by [ABateman](https://github.com/AndrewJBateman), email: gomezbateman@yahoo.com