forked from HackYourFuture/JavaScript2
-
Notifications
You must be signed in to change notification settings - Fork 28
Homework/exercises week 2 #54
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
Open
ebruispir
wants to merge
32
commits into
bitsagarob:master
Choose a base branch
from
ebruispir:JS-2-week-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
556faa9
Update index.js
ebruispir 7b766b7
Update app.js
ebruispir 1be02fb
Update style.css
ebruispir 85c7757
Add files via upload
ebruispir 844fa46
Update index.html
ebruispir 23e06b3
Update app.js
ebruispir c52e5c2
Update app.js
ebruispir 00f5b80
Update app.js
ebruispir 294b459
Update index.html
ebruispir b953e01
Update style.css
ebruispir 294c287
Create arrayExercise.js
ebruispir ab61391
Create index.html
ebruispir d1b651b
Update index.html
ebruispir 18ce1fb
Update index.html
ebruispir 588bae5
Create jsonExercise.js
ebruispir dda88dd
Update index.html
ebruispir 37d8dbb
Update map-filter.js
ebruispir 1ce1998
Update maartjes-work.js
ebruispir 61162bc
Update index.js
ebruispir 12ecfaa
Update app.js
ebruispir fa5374e
Delete Metamorphosis.jpg
ebruispir b0f2f6d
Delete a_clockwork_orange.jpg
ebruispir 59135b6
Delete animalfarm.jpg
ebruispir 7c57b42
Delete crime_and_punishment.jpg
ebruispir a405866
Delete les_miserables.jpg
ebruispir 3208e1c
Delete madonna_in_a_fur_coat.jpg
ebruispir 4952de2
Delete notes_from_underground.jpg
ebruispir 3e0eea5
Delete our_grand_despair.jpg
ebruispir e808623
Delete the_call_of_the_wild.jpg
ebruispir 20a1493
Delete the_nightingale.jpg
ebruispir df92f8e
Update index.html
ebruispir a5a05fb
Update style.css
ebruispir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| <!-- replace this with your HTML content --> | ||
| <!-- replace this with your HTML content --> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| /* add your styling here */ | ||
| /* add your styling here */ |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| 'use strict'; | ||
|
|
||
| /*Write a Javascript function to get first element of an array. | ||
| Passing a parameter 'n' will return the fist 'n' elements of the array.*/ | ||
|
|
||
| const numbers = [' one ', ' two ', ' three ', ' four ', ' five ']; | ||
| document.getElementById('array').innerHTML = 'Array :' + numbers; | ||
|
|
||
| function getFirstElement(array, index) { | ||
| const newArray = array.slice(0, index); | ||
| return newArray; | ||
| } | ||
|
|
||
| function callFistElement() { | ||
| document.getElementById('exe-1').innerHTML = getFirstElement(numbers, 3); | ||
| } | ||
|
|
||
| // ************************************** // | ||
|
|
||
| /* Write a Javascript program which accept a number as input an insert dashes (-) between | ||
| each two even numbers.For example if you accept 025468 the output should be 0-254-6-8. */ | ||
|
|
||
| function dashInsert(str) { | ||
| var arrayNumbers = str.split(''); | ||
| var newString = ''; | ||
| for (var i = 0; i < arrayNumbers.length; i++) { | ||
| if (arrayNumbers[i] % 2 === 0 && arrayNumbers[i + 1] % 2 === 0) { | ||
| newString = newString + arrayNumbers[i] + '-'; | ||
| } else { | ||
| newString = newString + arrayNumbers[i]; | ||
| } | ||
| } | ||
| return newString; | ||
| } | ||
| function callDashInsert() { | ||
| const inputValue = document.querySelector('input').value; | ||
| document.getElementById('exe-2').innerHTML = dashInsert(inputValue); | ||
| } | ||
|
|
||
| // ************************************** // | ||
|
|
||
| /* write a Javascript program to find the most frequent item of an array.*/ | ||
|
|
||
| const animals = [' cat ', ' dog ', ' bird ', ' lion ', ' cat ', ' dog ', ' cat ']; | ||
| document.getElementById('animals').innerHTML = 'Array :' + animals; | ||
|
|
||
| function mostFrequentItem(array) { | ||
| var result = array[0]; | ||
| var compare = 0; | ||
| for (var i = 0; i < array.length; i++) { | ||
| var count = 0; | ||
| for (var j = 0; j < array.length; j++) { | ||
| if (array[i] === array[j]) { | ||
| count++; | ||
| } | ||
| } | ||
| if (count > compare) { | ||
| compare = count; | ||
| result = array[i]; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| function callFrequentItem() { | ||
| document.getElementById('exe-3').innerHTML = mostFrequentItem(animals); | ||
| } | ||
|
|
||
| // ************************************** // | ||
|
|
||
| /* write a Javascript program which accept a string as input and swap the case of each | ||
| character.For example if you input 'The Quick Brown Fox' the output should be | ||
| 'tHE qUICK bROWN fOX' .*/ | ||
|
|
||
| function caseAlter(txt) { | ||
| var output = ''; | ||
|
|
||
| for (var i = 0; i < txt.length; i++) { | ||
| if (txt[i] == txt[i].toUpperCase()) { | ||
| output += txt[i].toLowerCase(); | ||
| } else { | ||
| output += txt[i].toUpperCase(); | ||
| } | ||
| } | ||
|
|
||
| return output; | ||
| } | ||
| function callCaseAlter() { | ||
| const input = document.getElementById('case-alter').value; | ||
| document.getElementById('exe-4').innerHTML = caseAlter(input); | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
| <title>week2 exercise1</title> | ||
| </head> | ||
| <body> | ||
| <h2>Exercise-1</h2> | ||
| <p id="array"></p> | ||
| <button onclick="callFistElement()">Result :</button> | ||
| <p id="exe-1"></p> | ||
| <h2>Exercise-2</h2> | ||
| <input type="text" value="Please enter numbers" /> | ||
| <p id="exe-2"></p> | ||
| <button onclick="callDashInsert()">Insert Dashes</button> | ||
| <h2>Exercise-3</h2> | ||
| <p id="animals"></p> | ||
| <button onclick="callFrequentItem()">Result :</button> | ||
| <p id="exe-3"></p> | ||
| <h1>Exercise-4</h1> | ||
| <input id="case-alter" type="text" /><br /><br /> | ||
| <button onclick="callCaseAlter() ">Result :</button> | ||
| <p id="exe-4"></p> | ||
| <script src="arrayExercise.js"></script> | ||
| <script src="jsonExercise.js"></script> | ||
| </body> | ||
| </html> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| //Write a JavaScript program to get the length of an JavaScript object. | ||
|
|
||
| var object; | ||
| object = { | ||
| "Country": "Belgium", | ||
| "Capital": "Brussels", | ||
| "Language": "French-Dutch", | ||
| }; | ||
|
|
||
| var getTheObjLength = key => { | ||
| return Object.keys(key).length; | ||
| }; | ||
|
|
||
| console.log(getTheObjLength(object)); | ||
|
|
||
|
|
||
| //Write a JavaScript function to check if an object contains given property. | ||
|
|
||
| var checkHaskey = (obj, key) => { | ||
| if (obj.hasOwnProperty(key)) { | ||
| console.log("Yes, I have " + key); | ||
| } else { | ||
| console.log("I have not " + key + " property"); | ||
| } | ||
|
|
||
| }; | ||
| console.log(checkHaskey(object, "Capital")); | ||
|
|
||
|
|
||
| //Write a JavaScript program to create a Clock. Console, every second :”14:37:42”,”14:37:43", “14:37:44”, "14:37:45" | ||
|
|
||
|
|
||
| function myClock() { | ||
| var today = new Date(); | ||
| var hours = today.getHours(); | ||
| var minutes = today.getMinutes(); | ||
| var seconds = today.getSeconds(); | ||
| console.log(hours + ":" + minutes + ":" + seconds); | ||
| }; | ||
| setInterval(myClock, 1000); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,16 +46,20 @@ const maartjesTasks = monday.concat(tuesday); | |
| const maartjesHourlyRate = 20; | ||
|
|
||
| function computeEarnings(tasks, hourlyRate) { | ||
| // Replace this comment and the next line with your code | ||
| console.log(tasks, hourlyRate); | ||
| const taskDurations = tasks | ||
| .map(task => task.duration / 60) | ||
| .filter(taskDuration => taskDuration >= 2) | ||
| .map(duration => duration * hourlyRate) | ||
| .reduce((acc, salary) => acc + salary) | ||
| .toFixed(2); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
| return taskDurations; | ||
| } | ||
|
|
||
|
|
||
| // eslint-disable-next-line no-unused-vars | ||
| const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); | ||
|
|
||
| // add code to convert `earnings` to a string rounded to two decimals (euro cents) | ||
|
|
||
| console.log(`Maartje has earned €${'replace this string with the earnings rounded to euro cents'}`); | ||
| console.log(`Maartje has earned €${earnings}`); | ||
|
|
||
| // Do not change or remove anything below this line | ||
| module.exports = { | ||
|
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this work? Should be tripple equals I think