This file contains 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
function shouter(whatToShout) { | |
// your code here | |
return whatToShout.toUpperCase() + "!!!"; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
Nothing to see here! |
This file contains 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
function celsToFahr(celsTemp) { | |
// your code here | |
return celsTemp*1.8+32; | |
} | |
function fahrToCels(fahrTemp) { | |
// your code here | |
return (fahrTemp-32)*1.8; | |
} |
This file contains 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
function main() { | |
try{ | |
doAllTheThings(); | |
} | |
catch(e){ | |
console.error(e); | |
reportError(e); | |
} | |
} |
This file contains 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
function makeList(item1, item2, item3) { | |
// your code here | |
const arr=[item1,item2,item3]; | |
return arr; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
This file contains 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
function shortWords(array) { | |
// your code goes here | |
const myArray = array.filter(word => word.length < 5); | |
return myArray; | |
} | |
/* From here down, you are not expected to | |
understand.... for now :) | |
This file contains 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
function fizzBuzz(countTo) { | |
// your code here | |
const arr=[]; | |
for(let i=1; i<=countTo; i++){ | |
if((i%3 === 0) && (i%5 === 0)){ | |
arr.push("fizzbuzz"); | |
} else if(i%3 === 0){ | |
arr.push("fizz"); | |
}else if(i%5 === 0){ |
This file contains 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
What is scope? Your explanation should include the idea of global vs. local scope. | |
Scope refers to the visibility of variables. Global variable will be avialable everywhere in program. The local variable will only be available in the code block where it was defined (for example: class or function). When you define a variable in a function that has the same name as a variable in the global scope, the local variable will take precedence over the global one. | |
Why are global variables avoided? | |
Global variables are hard to use together with other developers. A global variable can be changed to any part of the program and therefore it is difficult to control it especially in a large application. | |
Explain JavaScript's strict mode. | |
When strict mode is enabled all variables should be declared(for example let myVar="myVar"), for variables without declaration error will be triggered. The command "use strict" can be put at the top of file to enforce strict mode, or at the top of functionб, in this case, strict mode will |
This file contains 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
function createMyObject() { | |
// your code here | |
const myObject={ | |
foo: 'bar', | |
answerToUniverse:42, | |
'olly olly':'oxen free', | |
sayHello: function(){ | |
return 'hello'; | |
}, | |
}; |
This file contains 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
// you can pass in `scratchData` to test out `findByid` | |
// your function | |
const scratchData = [ | |
{ id: 22, foo: 'bar' }, | |
{ id: 28, foo: 'bizz' }, | |
{ id: 19, foo: 'bazz' }, | |
]; | |
function findById(items, idNum) { | |
// your code here |
This file contains 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
function getTokens(rawString) { | |
// Returns array of strings, with lower case, spaces and ,!.";:- - these simbols will be deleted | |
//regardless of how many times they were repeated and will be removed any falsy items from an array | |
// the array will be sorted alphabetically. As a result, an array of words is returned in the alphabetical order. | |
return rawString.toLowerCase().split(/[ ,!.";:-]+/).filter(Boolean).sort(); | |
} | |
function mostFrequentWord(text) { |
OlderNewer