Get help on our basic JavaScript and Algorithms Challenges. If you are posting code that is large use Gist - https://gist.github.com/ paste the link here.
// Setup
function phoneticLookup(val) {
var result = "";
// Only change code below this line
var lookup = {
"alpha": "Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta": "Denver",
"echo": "Easy",
"foxtrot":"Frank",
};
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup("charlie");
result = ....
something with val
and lookup
variables
function sumAll(arr) {
var max = Math.max.apply(Math, arr);
var min = Math.min.apply(Math, arr);
var result = 0;
for (; min <= max; min++) {
result += min;
}
return result;
}
sumAll([1, 4]);
function lookUp(firstName, prop){
// Only change code below this line
for (var i=0; i < contacts.lenght ; i++){
if(contacts[i].firstName == firstName){
if (contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}else{
return "No such property";
}
}
}
// Only change code above this line
}
please can someone help me
This an inline `<paste code here>
` code formatting with a single backtick(`) at start and end around the code
.
```js ⇦ Type 3 backticks and then press [shift + enter ⏎]
(type js or html or css)
<paste your code here>,
then press [shift + enter ⏎]
``` ⇦ Type 3 backticks, then press [enter ⏎]
See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics
push()
and shift()
, that's all you need to complete this challenge :-)
darelisss sends brownie points to @takumar and @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 2319 | @takumar | http://www.freecodecamp.com/takumar
:star: 523 | @bitgrower | http://www.freecodecamp.com/bitgrower
:bulb: to format code use backticks! ``` more info
:bulb: to format code use backticks! ``` more info
function lookUp(firstName, prop){
// Only change code below this line
for (var i=0; i < contacts.lenght ; i++){
if(contacts[i].firstName == firstName){
if (contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}else{
return "No such property";
}
}
}
// Only change code above this line
}
No such contact
in your code :-)
bitgrower sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star: 2320 | @takumar | http://www.freecodecamp.com/takumar
'''
function destroyer(arr) {
var mustRemove = [];
for (var i = 1; i < arguments.length; i++) {
arr = arr.filter(function(val){ return val != arguments[i];
});
(function(){return arr;})();
}
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);'''
:bulb: to format code use backticks! ``` more info
ssabu sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star: 1182 | @camperbot | http://www.freecodecamp.com/camperbot
function destroyer(arr) {
var mustRemove = [];
for (var i = 1; i < arguments.length; i++) {
arr = arr.filter(function(val){ return val != arguments[i];
});
(function(){return arr;})();
}
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
function factorialize(num) {
for(var i = 1 ; i <= num; i++) {
num *= i;
}
return num;
}
factorialize(5);
Why I'm getting an infinite loop? Shouldn't it finish when reaching i <= num?
ssabu sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 524 | @bitgrower | http://www.freecodecamp.com/bitgrower
frandarre sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 525 | @bitgrower | http://www.freecodecamp.com/bitgrower
frandarre sends brownie points to @obouchari and @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: frandarre already gave bitgrower points
:star: 334 | @obouchari | http://www.freecodecamp.com/obouchari
arr = arr.filter(function(val){ return val != arguments[i];
@SSabu -- I have a hard time figuring out exactly what js would do with that statement ... you might want to review Array.filter() in Mozilla Developer Network ... they have handy examples on the pages, too ...
function lookUp(firstName, prop){
// Only change code below this line
var j=1;
for (var i=0; i < contacts.length ; i++){
if(contacts[i].firstName === firstName){
if (contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}else{
return "No such property";
}
}else{
j++;
}
}
if (j== contacts.lenght){
return "No such contact";
}
// Only change code above this line
}
(function(){return arr;})();
for debuging ?
function factorialize(num) {
var n = num;
for(var i = 1; i < n; i++) {
num *= i;
}
if(num !== 0){
return num;
} else {
return 1;
}
}
factorialize(5);
This works. The 'if' is too cheeky or it's how it's supposed to be solved?
(function(){return arr;})();
inside the loop?
frandarre sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: frandarre already gave bitgrower points
ssabu sends brownie points to @obouchari :sparkles: :thumbsup: :sparkles:
:star: 335 | @obouchari | http://www.freecodecamp.com/obouchari
function destroyer(arr) {
var mustRemove = [];
for (var i = 1; i < arguments.length; i++) {
arr = arr.filter(function(val){ return val != arguments[i];
});
}
(function(){return arr;})();
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
okay...
let's not use IIFE's as an example ... let's just say I have a function, and within that function f(a), I call function b
arr = arr.filter(function(val){ return val != arguments[i]; // arguments[i] is not what you thinking
when I call function a -- an arguments object is created ...
when I call function b, yet another arguments object is created ... each one's is accessed by the special variable arguments
function(val) {};
ssabu sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: ssabu already gave bitgrower points
@SSabu
just thinking ... if u using this way
for (var i = 1; i < arguments.length; i++) {
arr = arr.filter(function(val){ return val != arguments[i];
});
}
u no need to really make a copy of the whole argumnent object..
ssabu sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 597 | @moigithub | http://www.freecodecamp.com/moigithub
function titleCase(str) {
var splitStrings = str.split(" ");
var stringStorage = splitStrings.map(function(val){
for (var i = 0; i < splitStrings; i++)
return val[i][0];
});
return stringStorage;
}
I know it isn't the answer, but i'm wondering why it's returning null for stringStorage. shouldn't it give me the first letter of the i-th item of the array?
ssabu sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:warning: ssabu already gave moigithub points
var splitStrings = str.split(" ");
splitStrings.map(function(val){
val
at first loop will be "hello"
return val[i][0];
val === "hello"
(at first loop)
Can anyone point out why my code is returning two for:
Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.
function chunk(arr, size) {
// Break it up.
result = [];
arr1 = arr.slice(0,size);
arr2 = arr.slice(size);
//return result.push(arr1, arr2);
return result.push(arr1, arr2);
}
chunk(["a", "b", "c", "d"], 2);
froyxx sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 598 | @moigithub | http://www.freecodecamp.com/moigithub
<script type="text/javascript">
/*<![CDATA[*/
var sportLink=[];
</script>
</head>
<body>
<form>
Select sport
<select id="sportlist" onchange="window.location.href=this.value">
<option></option>
<option value="http://www.espn.go.com/mlb">Baseball</option>
<option>Football</option>
<option>Hockey</option>
<option>Basketball</option>
<option>Tennis</option>
</select>
</form>
</body>
</html>
// Setup
function abTest(a, b) {
// Only change code below this line
// Only change code above this line
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}
// Change values below to test your code
abTest(2,2);
When a return statement is reached, the execution of the current function stops and control returns to the calling location.
Example
function myFun() {
console.log("Hello");
return "World";
console.log("byebye")
}
myFun();
The above outputs "Hello" to the console, returns "World", but "byebye" is never output, because the function exits at the return statement.
Instructions
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.
Not sure what to do with undefined and if I'm supposed to use a switch state or if
function doSomething(arg1, arg2) {
console.log(arg1);
console.log(arg2);
}
doSomething(1, 2);
// => "1"
// => "2"
doSomething();
// => "undefined"
// => "undefined"
function diff(arr1, arr2) {
var newArr = [];
// Same, same; but different.
newArr = newArr.concat(arr1, arr2);
newArr = newArr.filter(function (val) {
return !(arr1.indexOf(val) > -1 && arr2.indexOf(val) > -1);
});
return newArr;
}
diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Any better way than doing this ?
function where(collection, source) {
var arr = [];
var keyarr = [];
for(i=0;i<collection.length;i++){
if (collection[i].hasOwnProperty(Object.keys(source))){
arr.push(collection[i]);
}
}
return arr;
}
where([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
@cannelflow function golfScore(par, strokes) {
// Only change code below this line
if (1, 1){
return "Hole-in-one!";
}
else if(strokes <= par - 2){
return "Eagle";
}
if (1, 1){<-------if(1,1) means nothing do like if(strokes===1)
return "Hole-in-one!";
}
else if(strokes <= par - 2){<------this part is good
return "Eagle";
}
@Michelle2016
function destroyer(arr) {
var mustRemove = arr.splice(1, arr.length);
for (var i=0; i<mustRemove.length;i++)
var remove = mustRemove[i];
arr = arr.filter(function(val) { return val != remove;
});
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
@cannelflow Thank you for your help, I got it!
function golfScore(par, strokes) {
// Only change code below this line
if (strokes == 1){
return "Hole-in-one!";
}
else if(strokes <= par - 2){
return "Eagle";
}
else if (strokes == par - 1){
return "Birdie";
}
else if (strokes == par){
return "Par";
}
else if (strokes == par + 1){
return "Bogey";
}
else if (strokes == par + 2 ){
return "Double Bogey";
}
else if ( strokes >= par +3){
return "Go Home!";
}else{
return "Change Me";
}
// Only change code above this line
}
michelle2016 sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 799 | @cannelflow | http://www.freecodecamp.com/cannelflow
ssabu sends brownie points to @obouchari :sparkles: :thumbsup: :sparkles:
:star: 338 | @obouchari | http://www.freecodecamp.com/obouchari
or put another way .... (number of named-parameters) !== (number of arguments passed to the function)
...in this case ...
function foo() {
console.log(arguments); // { '0': 2, '1': 3 }
}
foo(2,3);
function destroyer(arr) {
//var mustRemove = arguments.splice(1, arr.length);
for (var i=1; i<arguments.length;i++)
var remove = arguments[i];
arr = arr.filter(function(val) { return val != remove;
});
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
[].slice(arguments, 1);
ssabu sends brownie points to @obouchari and @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: ssabu already gave obouchari points
:star: 526 | @bitgrower | http://www.freecodecamp.com/bitgrower
pythontutor
if you go into my profile http://freecodecamp.com/bitgrower -- you can click on my solution ...
NOW, let me tell you that I had kinda given up, so that's not original code ... HOWEVER, what I did do is sit down and understand, IN DETAIL why it works (well, with the exception of the line of code I stole from MDN) ...
var args = (arguments.length === 1?[arguments[0]]:Array.apply(null, arguments));
function bouncer(obj) {
if(!isNaN(obj)) {
return true;
}
}
var filtered = arr.filter(bouncer);
console.log(filtered);
bouncer([7, "ate", "", false, 9]);
Array.apply(null, arguments)
@bitgrower
several different assembly languages
Respect :+1:
gordondavidescu sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 527 | @bitgrower | http://www.freecodecamp.com/bitgrower
@rush86999
anybody know why this doesn’t work i am trying to pass a number or a “.” point in the if function
else if (!(isNaN(this.pressed) || (this.pressed == ".")
decimal point
function where(collection, source) {
var arr = [];
var keyarr = [];
for(i=0;i<collection.length;i++){
if (collection[i].hasOwnProperty(Object.keys(source))){
arr.push(collection[i]);
}
}
return arr;
}
where([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
typeof NaN
=== number :wink2:
@BLayman this will most certainly fail
if (collection[i].hasOwnProperty(Object.keys(source))){
if you read the return value of Object.keys you will notice that it returns an array of properties from the object you pass as an argument/parameter
function isExist(value)
{
if(value)
{
return false;
}
else
return true;
}
function destroyer(arr) {
// Remove all the values
for (var i = 1;i < arguments.length;i ++)
{
arguments[0].filter(isExist);
}
return arr;
}
@BLayman remember you have other types of loop that specialises on looping through properties as well
^^^ I'm all ears... :)
//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];
function lookUp(firstName, prop){
// Only change code below this line
for(var i = 0; i < contacts.length; i++){
if(firstName === contacts[i].firstName && prop === contacts[i].prop){
return contacts[i].prop;
}
if (firstName !== contacts[i].firstName){
return "No such contact";
}
if(prop !== contacts[i].prop){
return "No such property";
}
}
// Only change code above this line
}
// Change these values to test your function
lookUp("Akira", "likes");
This an inline `<paste code here>
` code formatting with a single backtick(`) at start and end around the code
.
```js ⇦ Type 3 backticks and then press [shift + enter ⏎]
(type js or html or css)
<paste your code here>,
then press [shift + enter ⏎]
``` ⇦ Type 3 backticks, then press [enter ⏎]
See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics
{
"firstName": "Akira",//<--------------------.firstName will work
"lastName": "Laine",//<---------------------.lastName will work
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
We'll pass you an array of two numbers. Return the sum of those two numbers and all numbers between them.
The lowest number will not always come first.
contacts[i][prop]
is the same as contacts[i].likes
or contacts[i]['likes']
if prop is equal likes that is
@wiscoay521 -- so break it down ...
you have 2 numbers, and they aren't in order ...
ah ... okay, maybe I need to put them in consistent order before I move on ... :)
@wearenotgroot
function lookUp(firstName, prop){
// Only change code below this line
for(var i = 0; i < contacts.length; i++){
if(firstName === contacts[i].firstName && prop === contacts[i].hasOwnProperty(prop)){
return contact[i][prop] ;
}
if (firstName !== contacts[i].firstName){
return "No such contact";
}
if(prop !== contacts[i].prop){
return "No such property";
}
}
// Only change code above this line
}
@bitgrower @wearenotgroot Ok, I think I have a strategy for getting the values associated with the keys. Use Object.keys() to make an array of the keys, then use that array to get the values associated with those keys. Something like this:
sourceKeys = Object.keys(source);
valueOfFirstKey = source.sourceKeys[0];
look about right?
return "No such contact"
bane of peoples existence
if(firstName === contacts[i].firstName && contacts[i].hasOwnProperty(prop))
blayman sends brownie points to @bitgrower and @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 844 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
:star: 528 | @bitgrower | http://www.freecodecamp.com/bitgrower
if (firstName !== contacts[i].firstName){
return "No such contact";
}
if(firstName === contacts[i].firstName)
{
}
else
{
}
hi All
function factorialize(num) {
var factorial;
var ans = 1;
for(i=0; i<num; i++){
factorial = num - i;
ans = ans * factorial;
}
return factorial;
}
factorialize(5);
whats is wrong with this code?
knnonah sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 845 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
ans
instead of factorial
function factorialize(num) {
var factorial;
var ans = 1;
for(i=0; i<num; i++){
factorial = num - i;
ans = ans * factorial; //<-----------------------stored the computed value on ans but returned factorial for some reason :)
}
return factorial; //<-------------returning the wrong thing, return ans instead
}
factorialize(5);
function steamroller(arr) {
// I'm a steamroller, baby
var result = [];
function flatten(stuff) {
for (i = 0; i < stuff.length; i++) {
if (Array.isArray(stuff[i])) {
flatten(stuff[i]);
} else {
result.push(stuff[i]);
}
}
}
flatten(arr);
return result;
}
This an inline `<paste code here>
` code formatting with a single backtick(`) at start and end around the code
.
```js ⇦ Type 3 backticks and then press [shift + enter ⏎]
(type js or html or css)
<paste your code here>,
then press [shift + enter ⏎]
``` ⇦ Type 3 backticks, then press [enter ⏎]
See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics
suhashosamani sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 846 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
if (Array.isArray(stuff[i])) {
result = result.concat(flatten(stuff[i]));
} else {
laevateiny sends brownie points to @masd925 and @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 984 | @masd925 | http://www.freecodecamp.com/masd925
:star: 847 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
for (var i = 0; i < stuff.length; i++) {
laevateiny sends brownie points to @bitgrower and @masd925 :sparkles: :thumbsup: :sparkles:
:warning: laevateiny already gave masd925 points
:star: 529 | @bitgrower | http://www.freecodecamp.com/bitgrower
This an inline `<paste code here>
` code formatting with a single backtick(`) at start and end around the code
.
```js ⇦ Type 3 backticks and then press [shift + enter ⏎]
(type js or html or css)
<paste your code here>,
then press [shift + enter ⏎]
``` ⇦ Type 3 backticks, then press [enter ⏎]
See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics
Hi All,
function palindrome(str) {
// Good luck!
var arr = [];
arr = str.split('');
arr.reverse();
revstr = arr.join('');
revstr = revstr.replace(/' '/g, '');
if(revstr === str){
return true;
}else{
return revstr;
}
}
palindrome("race car");
space is not getting removed.
var count = 0;
function cc(card) {
// Only change code below this line
if (card<1 && card<=6){
count =1+ card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
if (card >6 && card<=9){
count=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
if (card ===10 || card === 'J'|| card ==='Q'||card ==='K'||card =='A'){
count -=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
return "Change Me";
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
This an inline `<paste code here>
` code formatting with a single backtick(`) at start and end around the code
.
```js ⇦ Type 3 backticks and then press [shift + enter ⏎]
(type js or html or css)
<paste your code here>,
then press [shift + enter ⏎]
``` ⇦ Type 3 backticks, then press [enter ⏎]
See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics
revstr = revstr.replace(/\s/g, '');
str = str.replace(/\s/g, '');
this worked guys
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
var capitalized;
function titleCase(str) {
var splitStr = str.split(" ");
for (i = 0; i< str.length; i++){
var capitalized = splitStr.capitalizeFirstLetter();
return capitalized;
}
}
slice()
on an array without passing any argument?
'var count = 0;
function cc(card) {
// Only change code below this line
if (card<1 && card<=6){
count =1+ card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
if (card >6 && card<=9){
count=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
if (card ===10 || card === 'J'|| card ==='Q'||card ==='K'||card =='A'){
count -=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
return "Change Me";
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
'
:bulb: to format code use backticks! ``` more info
'''var count = 0;
function cc(card) {
// Only change code below this line
if (card<1 && card<=6){
count =1+ card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
if (card >6 && card<=9){
count=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
if (card ===10 || card === 'J'|| card ==='Q'||card ==='K'||card =='A'){
count -=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
return "Change Me";
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
'''
:bulb: to format code use backticks! ``` more info
efhjones sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 985 | @masd925 | http://www.freecodecamp.com/masd925
```var count = 0;
function cc(card) {
// Only change code below this line
if (card<1 && card<=6){
count =1+ card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
if (card >6 && card<=9){
count=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
if (card ===10 || card === 'J'|| card ==='Q'||card ==='K'||card =='A'){
count -=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
return "Change Me";
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');```
var count = 0;
function cc(card) {
// Only change code below this line
if (card<1 && card<=6){
count =1+ card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
if (card >6 && card<=9){
count=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
if (card ===10 || card === 'J'|| card ==='Q'||card ==='K'||card =='A'){
count -=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}
}
return "Change Me";
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
Hi, are there other ways to write Seek and Destroy without indexOf ?
```/jshint esversion: 6 /
function destroyer(arr, ...args) {
arr = arr.filter(function(val) {
if(args.indexOf(val) == -1) {
return val;
}
});
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);```
Thanks!
function convert(celsius) {
// Only change code below this line
myVar=(9/5)+32;
// Only change code above this line
if ( typeof fahrenheit !== 'undefined' ) {
return fahrenheit;
} else {
return 'fahrenheit not defined';
}
}
// Change the inputs below to test your code
convert(0);
How to Create a variable fahrenheit and apply the algorithm to assign it the corresponding temperature in Fahrenheit.?
// Only change code below this line
function update(id, prop, value) {
if(value !== "" && prop !== "tracks") {
collection[id][prop] = value;
}
if(prop == "tracks" && value !== "") {
collection[id][prop].push(value);
}
if(value === "") {
delete collection[id][prop];
}
return collection;
}
slice()
on an array without passing any argument?
theosarran sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 533 | @bitgrower | http://www.freecodecamp.com/bitgrower
function lookUp(firstName, prop){
for (var i = 0; i < contacts.length; i++){
if ((firstName == contacts[i].firstName) && (contacts[i].hasOwnProperty(prop))){
return contacts[i][prop];
}
else if( firstName !== contacts[i].firstName) {
return "No such contact";
}
}
// Only change code below this line
// Only change code above this line
}
// Change these values to test your function
lookUp("Kristian", "lastName");
I'm working on the simon game. I have an array of divs that need to be clicked, but I want a delay between each click.
Here is my loop :
for(var i =0; i<sequence.length; i++){
$("#div" +sequence[i]).click();
}
I tried using setTimeOut, but I can't call functions inside loops. How do I do it?
I'm working on the simon game. I have an array of divs that need to be clicked, but I want a delay between each click. Here is my loop :
for(var i =0; i<sequence.length; i++){
$("#div" +sequence[i]).click();
}
I tried using setTimeOut, but I can't call functions inside loops. How do I do it?
function update(id, prop, value) {
if(value !== "" && prop !== "tracks") {
collection[id][prop] = value;
}
if(prop == "tracks" && value !== "") {
collection[id][prop].push(value);
}
if(value === "") {
delete collection[id][prop];
}
return collection;
}
myVar= fahrenheit;
myVar=*9/5+32;
`
myVar=*9/5+32; //<------------where is the celsius?
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];
function lookUp(firstName, prop){
for (var i = 0; i < contacts.length; i++){
if ((firstName === contacts[i].firstName) && (contacts[i].hasOwnProperty(prop))){
return contacts[i][prop];
}
else if( firstName !== contacts[i].firstName) {
return firstName
;
}
}
// Only change code below this line
// Only change code above this line
}
// Change these values to test your function
lookUp("Kristian", "lastNa
codernoob sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 848 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
casadaro sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 849 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
function lookUp(firstName, prop){
for (var i = 0; i < contacts.length; i++){
if (firstName === contacts[i].firstName && (contacts[i].hasOwnProperty(prop))){
return contacts[i][prop];
}
else if (firstName !== contacts.firstName) {
return "No such contact";
}
}
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
},
];
if (firstName === contacts[i].firstName && (contacts[i].hasOwnProperty(prop))){
return contacts[i][prop];
}
else if (firstName !== contacts.firstName) {
return "No such contact";
}
var celcius=(30);
function farenhight(celcius ) {
var farenheight =celsius * 9/5 +32};
check please
for (var i = 0; i < contacts.length; i++){
if (firstName === contacts[i].firstName && (contacts[i].hasOwnProperty(prop))){
return contacts[i][prop];
}
else if (firstName !== contacts.firstName) { //<--------------------if we remove this the loop continues if the first if test is false
return "No such contact"; //<---------------where to move this??
}
}
george-of-croton sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 850 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
neeraj-lad sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 851 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
"http://api.openweathermap.org/data/2.5/weather?callback=?lat=" + Math.round(latitude) + "&lon=" + Math.round(longitude) + "&appid=44db6a862fba0b067b1930da0d769e98";
?callback=?
@neeraj-lad this part
"http://api.openweathermap.org/data/2.5/weather?callback=?lat="
vs
"http://api.openweathermap.org/data/2.5/weather?lat="
{"cod":"404","message":"Error: Not found city"}
}
if ( firstName !== contacts.firstName ){
result = "No such contact";
}
else if (prop !== contacts[prop] ){
result = "No such property";
}
this is not working for me
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
openWeatherURL += "http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&appid=44db6a862fba0b067b1930da0d769e98";
$(document).ready(function () {
var openWeatherURL = "";
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
console.log(position);
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
openWeatherURL = "http://api.openweathermap.org/data/2.5/weather?callback=?";
$.getJSON(openWeatherURL,{lat:latitude,lon:longitude, APPID:'44db6a862fba0b067b1930da0d769e98'}, function(json){
console.log(json);
var city = json["name"];
var country = json["sys"]["country"];
var location = city + ", " + country;
var weatherDesc = json["weather"][0]["description"];
var windSpeed = json["wind"]["speed"];
$(".location").html("<h3>" + location + "</h3>");
$(".weather-desc").html("<h3>" + weatherDesc + "</h3>");
$(".wind-speed").html("<h3>" + windSpeed + " meter/sec</h3>");
}); //end getJSON
}); //end navigator.geolocation if clause
}
}); //end document ready
function lookUp(firstName, prop){
for (var i = 0; i < contacts.length; i++){
if (firstName === contacts[i].firstName && (contacts[i].hasOwnProperty(prop))){
return contacts[i][prop];
}
}
if ( firstName !== contacts.firstName ){
result = "No such contact";
}
else if (!contacts.hasOwnProperty(prop) ){
result = "No such property";
}
return result;
// Only change code below this line
// Only change code above this line
}
// Change these values to test your function
lookUp("Harry", "address");
Mixed Content: The page at 'https://s.codepen.io/neeraj-lad/fullpage/dGadyX?' was loaded over HTTPS, but requested an insecure script 'http://api.openweathermap.org/data/2.5/weather?callback=jQuery2130792804101…2002&lon=73.0437446&APPID=44db6a862fba0b067b1930da0d769e98&_=1455524804055'. This request has been blocked; the content must be served over HTTPS.
openWeatherURL = "https://crossorigin.me/http://api.openweathermap.org/data/2.5/weather?callback=?";
neeraj-lad sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:warning: neeraj-lad already gave wearenotgroot points
@wearenotgroot
function palindrome(str) {
// Good luck!
var arr = [];
arr = str.split('');
arr.reverse();
revstr = arr.join('');
revstr = revstr.replace(/[,. ]/g, '').toLowerCase();
str = str.replace(/[,. ]/g, '').toLowerCase();
if(revstr === str){
return true;
}else{
return false;
}
}
palindrome("0_0 (: /-\ :) 0-0");
this last string is failing
}
if ( firstName !== contacts.firstName ){
result = "No such contact";
}
else if (prop !== contacts.hasOwnProperty(prop) ){
result = "No such property";
}
i cannot get this bottom part to return correctly
function lookUp(firstName, prop){
for (var i = 0; i < contacts.length; i++){
if (firstName === contacts[i].firstName && (contacts[i].hasOwnProperty(prop))){
return contacts[i][prop];
}
else if (!contacts.hasOwnProperty(prop) ){
result = "No such property"; //<----------this part you can just return no such property immediately, return "No such property"
}
}
return "No such contact";
// Only change code above this line
}
@wearenotgroot
revstr = revstr.replace(/[,._ ]/g, '').toLowerCase();
str = str.replace(/[,._ ]/g, '').toLowerCase();
not working
[\W_]
// Setup
function phoneticLookup(val) {
var result = "";
// Only change code below this line
var lookup = {
alpha: "Adams",
bravo: "Boston",
charlie: "Chicago",
delta: "Denver",
echo: "Easy",
foxtrot: "Frank"
};
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup("charlie");
' ' '
var count = 0;
function cc(card) {
// Only change code below this line
switch(card){
case 2:
count+=1;
return count + " Bet";
case 3:
count+=1;
return count+" Bet";
case 4:
count+=1;
return count+" Bet";
case 5:
count+=1;
return count+" Bet";
case 6:
count+=1;
return count+" Bet";
case 7:
count=0;
return count+"Bet";
case 8:
count=0;
return count+"Bet";
case 9:
count=0;
return count+" Bet";
case 'K':
count-=1;
return count+" Bet";
case 'J':
count-=1;
return count+" Bet";
case 'Q':
count-=1;
return count+" Bet";
case 'A':
count-=1;
return count+" Bet";
}
return "Change Me";
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
' ' '