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.
if (contacts[0].firstName === firstName) {
if (contacts[0].hasOwnProperty(prop)) {
return contacts[0][prop];
product *= arr[i][j]
but works perfectly fine the way you have it
andercodder sends brownie points to @dueldrawer8 :sparkles: :thumbsup: :sparkles:
:cookie: 423 | @dueldrawer8 |http://www.freecodecamp.com/dueldrawer8
oMove: ['1']
, and the next object should have oMove: ['2']
, instead they all have oMove: [1,2,3,4,5,6,7,8]
sirus3020 sends brownie points to @jluboff and @adamakers :sparkles: :thumbsup: :sparkles:
:cookie: 647 | @jluboff |http://www.freecodecamp.com/jluboff
:cookie: 317 | @adamakers |http://www.freecodecamp.com/adamakers
var arr = [''hello world'', "my name is"];
for (var i = 0; i < arr.length: i++) {
arr[i].split(' ');
}
i'm having trouble understanding this function:
function permute(string) {
function recur(string, prefix) {
if (string.length === 0) {
return [prefix];
} else {
var out = [];
for (var i = 0; i < string.length; i++) {
var pre = string.substring(0, i);
var post = string.substring(i + 1);
out = out.concat(recur(pre + post, string[i] + prefix));
}
return out;
}
}
var distinct = {};
recur(string, "").forEach(function(result) {
distinct[result] = true;
});
return Object.keys(distinct);
}
in the recursive function, when is string.length ever === 0?
answer
variable
a
b
c
defaultStatement
function getProductOfAllElementsAtProperty(obj, key) {
// your code here
for(var strange in obj){
if(Array.isArray(obj[strange])){
var total = 1;
for(var i = 0; i < obj[strange].length; i++){
total*= obj[key][i];
}
}
else if(obj[strange].length < 0){
return 0;
}
else{
return 0;
}
}
return total;
}
var obj = {
key: []
};
var output = getProductOfAllElementsAtProperty(obj, 'key');
console.log(output);
wondering why if i have an empty array it isnt returning 0 rather than 1?
function sumPrimes(num) {
var res = 0;
// Function to get the primes up to max in an array
function getPrimes(max) {
var sieve = [];
var i;
var j;
var primes = [];
for (i = 2; i <= max; ++i) {
if (!sieve[i]) {
// i has not been marked -- it is prime
primes.push(i);
for (j = i << 1; j <= max; j += i) {
sieve[j] = true;
}
}
}
return primes;
}
// Add the primes
var primes = getPrimes(num);
for (var p = 0; p < primes.length; p++) {
res += primes[p];
}
return res;
}
// test here
sumPrimes(10);
if I do
var testArr = ['1', '2', '3', '4', '5'];
var obj = {
things: []
}
testArr.forEach(function(item){
var newObj = Object.create(obj);
newObj.things.push(item);
console.log(newObj)
});
then why does each obj have a prop of things: ['1', '2', '3', '4', '5'] instead of one object having
things:['1']and the next object having
things: ['2']```?
obj
correct?) instead of the newObj?
// Setup
var myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];
// Only change code below this line
var secondTree = ""; // Change this line
、、、
newObj.things = [item];
that would create a new array each time.
sieve[2]
doesn't exist so is undefined !sieve[2] is true so the if passes the test.shawnchenxmu sends brownie points to @adamakers :sparkles: :thumbsup: :sparkles:
:cookie: 318 | @adamakers |http://www.freecodecamp.com/adamakers
function rot13(str) { // LBH QVQ VG!
var dec="";
function name(str){
var s=[];
for(var i=0; i<str.length; i++)
{
s[i] = (str.charCodeAt(i)-65+13)%26+65;
}
return s;
}
dec.fromCharCode(name(str));
dec.join("");
return dec;
}
//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 lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
if (contacts[i].firstName === firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
}
return "No such property";
}
return "No such contact";
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Kristian", "lastName");
var Bike = function() {
// Only change code below this line.
var gear=0;
this.setGear=function(change){
gear += change;
};
this.getGear = function(){
return gear;
};
};
var myCar = new Car();
var myBike = new Bike();
Handling of 'touchstart' input event was delayed for 164 ms due to main thread being busy. Consider marking event handler as 'passive' to make the page more responsive.
shawnchenxmu sends brownie points to @adamakers :sparkles: :thumbsup: :sparkles:
:warning: shawnchenxmu already gave adamakers points
@sjames1958gm Okay, thank you so much for "Explaining it like I'm 5" That seriously helped :) (I know that may sound like sarcasm. But, no sarcasm!) So it all makes sense up until this point:
for (j = i << 1; j <= max; j += i) {
sieve[j] = true;
So, first line --> I'm reading that << has something to do with binary notation? I do understand that this section has something to do with all following multiples created from i value. So, i = 2 would propogate 4, 6, 8, 10 (If the input was 10). So I don't understand the << ..... and if sieve[j] = true (or even if it equaled false...) so what? I don't see what happens there.
:star2: 5373 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
mzedlach sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
+=
I would just use... gear=change
vzambrano98 sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1833 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
@sjames1958gm
function getProductOfAllElementsAtProperty(obj, key) {
// your code here
for(var strange in obj){
if(obj[strange].length > 0){
var total = 1;
for(var i = 0; i < obj[strange].length; i++){
total*= obj[key][i];
}
return total;
}
else if(!Array.isArray(obj[strange])){
return 0;
}
}
}
var obj = {
key: []
};
var output = getProductOfAllElementsAtProperty(obj, 'key');
console.log(output);
now if the property at the key is an empty array..it needs to return 0 but it is returning undefined
hello...
Is it legal to assign IIFE to a variable?
Like
var m = (foo(){
var a = 2;
return a;
}();
Is this legal? Does it have any bad side effects?
function getProductOfAllElementsAtProperty(obj, key) {
for(var strange in obj){
var total = 1;
if(Array.isArray(obj[strange]) && obj[strange].length > 0){
for(var i = 0; i < obj[strange].length; i++){
total*= obj[key][i];
}
return total;
}
else{
return 0;
}
}
}
Im having a little problem figuring out what's wrong here:
var count = 0;
function cc(card) {
// Only change code below this line
for (card) {
if (card =2,3,5,6) {
count ++;
} else (card =10, 'J', 'Q','K','A') {
count --;
}
}
}
return count;
Could use some help with the Babel compilier.
http://codepen.io/JTKnox91/pen/zNxyXP?editors=0010
Look at line 1134 uncomplied and line 1443 compilied.
Usually any this
is turned into _thisXX
. For instance this.player
in the uncompiled constructor for Map becomes _this23.player
. In the I am expecting line 1134 to compile into _thisXX.player.location
but instead remains as this.player.location
, which is undefined when that method is called. What am I doing wrong here that's stopping the Babel from compiling that method the way it compiles the other methods?
function nextInLine(arr, item) {
// Your code here
return item; // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
hi guys any help here?
function titleCase(str) {
var arrayNew = str.split(" ");
for(var i= 0; i<arrayNew.length; i++){
arrayNew[i].charAt(0).toUpperCase();
equis = arrayNew.join(" ");
}
return equis;
}
titleCase("I'm a little tea pot");
do you know why the code is not working?
@y0el22
function titleCase(str) {
var arrayNew = str.split(" ");
for(var i= 0; i<arrayNew.length; i++){
arrayNew[i].charAt(0).toUpperCase(); //this doesn't actually assign anything, try " arrayNew[i] = ..." and then what you had written before.
equis = arrayNew.join(" "); //this only needs to be done once, so you could move it out of the for loop
}
return equis;
}
titleCase("I'm a little tea pot");
Let me know how those changes work
andrewscr sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5374 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
So on one of the lessons it says that this:
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};
// Only change code below this line;
var playerNumber = 16; // Change this Line
var player = testObj[playerNumber]; // Change this Line
prints out "Montana"
but i put it in the browser console and it says undefined ..why is that?
var a = 'a';
var capitalA = a.toUpperCase();
// a is still 'a' and capitalA is 'A'
help ```
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i=0; i < multiplyAll.length; i++){
}
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
```
function multiplyallarr var product 1 only change code below this line for var i0 i multiplyalllength i only change code above this line return product modify values below to test your codemultiplyall1234567
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i=0; i < multiplyAll.length; i++){
}
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
testObj
in the console
function lookUpProfile(firstName, prop){
// Only change code below this line
var hasName = false;
for(var i=0; i< contacts.length; i++){
if(contacts[i].firstName == firstName){
hasName = true;
if(contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}
return "No such property";
}
}
if(hasName === false){return "No such contact";}
// Only change code above this line
}
:bulb: to format code use backticks! ``` more info
tacojoe sends brownie points to @veksen :sparkles: :thumbsup: :sparkles:
:cookie: 109 | @veksen |http://www.freecodecamp.com/veksen
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT")
and titleCase("sHoRt AnD sToUt")
need it
retartedzombie sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5375 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Not quite sure what im missing here, should return a count of -5, i think:
var count = 0;
function cc(card) {
// Only change code below this line
if (card == 2,3,4,5,6) {
return count ++;
} else if (card == 10, 'K', 'Q', 'J', 'A') {
return count --;
}
return count;
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i=0; i < arr.length; i++){
if(Array.isArray(arr[i])) {
product = arr[i].reduce(function(a,e) {
return a * e
}, product);
} else {
product *= arr[i];
}
}
// Only change code above this line
return product;
}
var customerData = {
'Joe': {
visits: 1
},
'Carol': {
visits: 2
},
'Howard': {
visits: 3
},
'Carrie': {
visits: 4
}
};
function greetCustomer(firstName) {
var greeting = '';
if(customerData['firstName'].visits === 1){
greeting = "Welcome back, " + firstName + "! We're glad you liked us the first time!"
}else if()
return greeting;
}
greetCustomer("Joe")
@sjames1958gm can you explain why this returns "4":
var count = 0;
function cc(card) {
// Only change code below this line
if (card == 2 || card == 3 || card == 4 || card ==5 || card == 6) {
return count ++;
} else if (card == 10 || card == 'K' ||card == 'Q' ||card == 'J' ||card == 'A') {
return count --;
}
return count;
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);
johnnunns sends brownie points to @raghu-nx :sparkles: :thumbsup: :sparkles:
:cookie: 286 | @raghu-nx |http://www.freecodecamp.com/raghu-nx
colinmac17 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5376 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
\
is out of place there should be a \
escaped after SecondLine
\r
and then remove all the spaces
i need help```function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i = 0; i < arr.length[i]; i++){
product *= arr1;
}
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
```
andrewscr sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: andrewscr already gave sjames1958gm points
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i = 0; i < arr.length[i]; i++){
product *= arr[1];
}
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
[i]
in your loop
I'm still not sure why this is returning "5":
var count = 0;
function cc(card) {
// Only change code below this line
if (card == 2 || card == 3 || card == 4 || card ==5 || card == 6) {
count ++;
} else if (card == 10 || card == 'K' ||card == 'Q' ||card == 'J' ||card == 'A') {
count --;
}
return count;
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);
:bulb: to format code use backticks! ``` more info
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i = 0; i < arr.length; i++){
for (var j = 0; j < arr[i].length; j++){
product *= arr[i][j];
}
}
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
var myStr = "FirstLine\n\\SecondLine\\rThirdLine"; // Change this line
var customerData = {
'Joe': {
visits: 1
},
'Carol': {
visits: 2
},
'Howard': {
visits: 3
},
'Carrie': {
visits: 4
}
};
function greetCustomer(firstName) {
var greeting = '';
if(customerData[firstName] !== firstName){
greeting = "Welcome! Is this your first time?"
}if(customerData[firstName].visits === 1){
greeting = "Welcome back, " + firstName + "! We're glad you liked us the first time!"
}else {
greeting = "Welcome back, " + firstName + "! So glad to see you again!"
}
return greeting;
}
greetCustomer("John")
// Example
var ourArray = [];
for (var i = 0; i < 5; i++) {
ourArray.push(i);
}
// Setup
var myArray = [];
// Only change code below this line.
for (var i = 0; i <= 5; i++) {
myArray.push(i);
}
i<=5
should be i<5
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
My myAdjective myNoun myAdverb myVerb straight into the pile of leaves.
// Your code above this line
return result;
}
// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
You will need to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb.
You will also need to use additional strings, which will not change, and must be in between all of the provided words. The output should be a complete sentence.
We have provided a framework for testing your results with different words. The tests will run your function with several different inputs to make sure all of the provided words appear in the output, as well as your extra strings.
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
// Your code above this line
return result;
}
// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
corycmyers sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star2: 1697 | @dhcodes |http://www.freecodecamp.com/dhcodes
// Setup
var myStr = "Jello World";
// Only change code below this line
myStr = "Hello World";
myStr[0] = "H"; // Fix Me
can anyone tell me why this isn't working for me. I am new to all this
var myStr = "FirstLine\n\\SecondLine\rThirdLine"; // Change this line
if(customerData[firstName].visits === 1)
and for "Joe" it doesn't exist so you will get an error
"My "+
myAdjective ?
celsius
@krittiyaclark
longorjames sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star2: 1698 | @dhcodes |http://www.freecodecamp.com/dhcodes
:warning: longorjames already gave dhcodes points
longorjames sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
@dhcodes I got this --> function convertToF(celsius) {
var fahrenheit = (celsius(9/5))+32;
// Only change code below this line
// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(0);
*
to multiplicate values
*
after celsius
function reverseString(str) {
var array=str.split(" ");
for(i=0;i<array.length;i++){
array[i]=array[i].reverse();
}
str=array.join(" ");
return str;
}
reverseString("Greetings from Earth");
krittiyaclark sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star2: 1699 | @dhcodes |http://www.freecodecamp.com/dhcodes
""
array[i]
is a string
function reverseString(str) {
var array=[];
array=str.split(" ");
for(i=0;i<array.length;i++){
array[i]=array[i].reverse();
}
str=array.join(" ");
return str;
}
reverseString("Greetings from Earth");
reverse()
on a string
""
and then run reverse on that
@Manish-Giri // Declare your variable here
var myGlobal = [10];
function fun1() {var myGlobal = 10; return myGlobal;}
// Assign 5 to oopsGlobal Here
oopsGlobal = [5];
function fun2() {oopsGlobal = 5; return oopsGlobal;}
// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}
var myGlobal = [10];
oopsGlobal = [5];
// Declare your variable here
//myGlobal here
function fun1() {
// Assign 5 to oopsGlobal Here
//your oopsGlobal assignment should be here
}
function fun1() {var myGlobal = 10; return myGlobal;}
// Assign 5 to oopsGlobal Here
oopsGlobal = [5];
function fun2() {oopsGlobal = 5; return oopsGlobal;}
krate2016 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 3829 | @manish-giri |http://www.freecodecamp.com/manish-giri
function reverseString(str) {
var array=[];
array=str.split(" ");
array.reverse();
str=array.join(" ");
return str;
}
reverseString("Greetings from Earth");
@alimily this is your expected output
reverseString("Greetings from Earth") should return "htraE morf sgniteerG".
this is your actual output -
"Earth from Greetings"
str = str.split(" ");
1 2 3
becomes 3 2 1
hi, help to solve this challenge(chunkey monkey),
function chunkArrayInGroups(arr, size) {
// Break it up.
if(size<=arr.length){
return arr.slice(0,size);
}else
return "it's out of array";
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
Evening! Some assistance would be greatly appreciated! I'm getting a message saying break is unreachable after return.
var count = 0;
function cc(card) {
// Only change code below this line
switch(card){
case (2):
case (3):
case (4):
case (5):
case (6):
return count + 1;
break;
case (7):
case (8):
case (9):
return count;
break;
case (10):
case ('J'):
case ('Q'):
case ('K'):
case ('A'):
return count - 1;
break;
}
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 myVar = 87;
// Only change code below this line
myVar = ++myVar;
var myVar = 87;
// Only change code below this line
myVar = ++myVar;
coolcoder007 sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 827 | @gregatgit |http://www.freecodecamp.com/gregatgit
@coolcoder007
var num = 5;
num = num + 1; // 6
num += 1; // 7
num++; // 8
See how the one for getting num
from 7
to 8
doesn't use the assignment operator (=
)?
The lesson is requesting that you recreate that process so that you know how to increment and decrement a number with short notation.
card
parameter. You're supposed to increment or decrement the global count
variable according to the card
's valuecard
parameter is 2, 3, 4, 5 or 6 you need to increment the global variable count
.card
parameter is 10, 'J', 'Q', 'K' or 'A' you need to decrement the global variable count
.count
and the string "Bet" if the count
is positive, or "Hold" if the count is zero or negative.count
and the player's decision ("Bet" or "Hold") should be separated by a single space.
Need some help
How do you make a selectbox with the switch statement ?
<select>
<optgroup>Group 1</optgroup>
<option>1</option>
<option>2</option>
<option>3</option>
<optgroup>Group 2</optgroup>
etc
@revisualize Hey Joseph good timing :D
jothetraveler sends brownie points to @gregatgit and @revisualize :sparkles: :thumbsup: :sparkles:
:cookie: 828 | @gregatgit |http://www.freecodecamp.com/gregatgit
:star2: 2995 | @revisualize |http://www.freecodecamp.com/revisualize
function caseInSwitch(val) {
var answer = "";
switch (val) {
case 1:
answer = "alpha";
break;
Can anyone explain what i'm doing wrong here?
```function myReplace(str, before, after) {
var newStr = str.split(' ');
var index = newStr.indexOf(before);
if (index !== -1) {
if (index[0] === index[0].toUpperCase())
newStr[index] = after[0].toUpperCase() + after.slice(1);
}
//capitalization
return newStr.join(' ');
}
myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
```
function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val) {
case 1:
answer = "alpha";
break;
case 2:
answer = "beta";
break;
case 3:
answer = "gamma";
break;
case 4:
answer = "delta";
// Only change code above this line
return answer; }
}
return answer; }
barrystepp sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2996 | @revisualize |http://www.freecodecamp.com/revisualize
index
is a number.
sperrye sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2997 | @revisualize |http://www.freecodecamp.com/revisualize
@revisualize OOOhh, misunderstood the question, if the user CLICKS a genre the user needs to see the movies of that genre :laughing:
example
case '0':
document.getElementById('v').innerHTML ='<ul><li>example<li></ul>';
break;
function
?
var contacts = [ { ... } , { ... } , { ... } , { ... } ];
Hi everyone, I often get stuck at 'why only looping once' problem...like this twitch project
https://jsfiddle.net/k456czcm/
though it logs every stram IDs i set up, it just can't return all the streams IDs into HTML
wonder anyone could help me? thanks.
I encountered similar problems lots of time while doing other projects, but I just couldn't figure out ... /_\
@revisualize hi, I am stuck here, Pls look into,
function chunkArrayInGroups(arr, size) {
// Break it up.
var newArray= [];
for(var i=0; i<arr.length; i++){
newArray.push(arr.slice(0,size));
arr= arr.slice(size);
}
return newArray;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine
// Setup
function phoneticLookup(val) {
var result = "";
// Only change code below this line
val = {
"alpha": "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"delta": "Denver",
"echo": "Easy",
"foxtrot": "Frank",
"": undefined
};
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup("alpha");
val
parameter
hi, I am stuck here, Pls look into,
function chunkArrayInGroups(arr, size) {
// Break it up.
var newArray= [];
for(var i=0; i<arr.length; i++){
newArray.push(arr.slice(0,size));
arr= arr.slice(size);
}
return newArray;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
i
as you iterate across your array (arr
).
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i=0; i < arr.length; i++) {
for (var j=0; j< arr[i].length; j++) {
product = product * arr[i][j]*arr[i++][j++];
}
}
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
product = product arr[i][j]arr[i++][j++] is this sentence wrong?
*arr[i++][j++];
tanpaopao sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3001 | @revisualize |http://www.freecodecamp.com/revisualize
function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
farenheit=(celsius *(9/5))+32;
// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(0);
convertToF(-30);
convertToF(-10);
convertToF(0);
farenheit
is misspelled.
fahrenheit
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
var myNoun = "dog";
var myStr = "Hello my name is" + myNoun + "i am a" + wordBlanks[wordBlanks.length -3] + "that" + wordBlanks[wordBlanks.length -2] + "very" + wordBlanks[wordBlanks.length -1] + "HOWS THAT?";
// Your code above this line
return result;
}
// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
tanpaopao sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: tanpaopao already gave revisualize points
@coymeetsworld thanks! but sorry i don't quite understand...you mean this part
if (data.stream === null) {
showName = channelName;
showOnline = 'Offline';
showLogo = 'http://s.jtvnw.net/jtv_user_pictures/hosted_images/GlitchIcon_PurpleonWhite.png';
showUrl = 'https://www.twitch.tv/'+channelName+'';
} else if (data.stream === undefined) {
showName = 'Accnount Closed';
showOnline = 'Account Closed'
showLogo = 'http://s.jtvnw.net/jtv_user_pictures/hosted_images/GlitchIcon_PurpleonWhite.png';
showUrl = 'Account Closed';
} else {
showName = data.stream.channel.status;
showOnline = 'Online';
showLogo = data.stream.channel.logo;
showUrl = data.stream.channel.url;
}
console.log(showName, showOnline, showLogo, showUrl);
renderHTML();
should move out from request.onload function?
moist17 sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1834 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb)
giving the function name as wordBlanks
myNoun
, myAdjective
, myVerb
and myAdverb`.gameruler1 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3002 | @revisualize |http://www.freecodecamp.com/revisualize
// 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",
"": undefined
};
result = lookup[val];
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup("charlie");
var url = 'https://wind-bow.gomix.me/twitch-api/streams/'+channelName+'';
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.onload = function() {
ezraplato sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3003 | @revisualize |http://www.freecodecamp.com/revisualize
coolcoder007 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3004 | @revisualize |http://www.freecodecamp.com/revisualize
function convertCF(num, scale){
if (scale === "c") {
return (num - 32) * 5 / 9;
} else if (scale === "f") {
return (num * 9/5) + 32
} else if (scale === null || scale === '') {
return (num - 32) * 5 / 9;
} else {
throw Error;
}
}
can someone see why this function isn't passing?
myNoun = wordBlanks[wordBlanks.length -4].
myStr = "Hello my name is" + myNoun + "i am a" + myAdjective + "that" + myVerb + "very" + myAdverb + "HOWS THAT?";
myNoun = wordBlanks[wordBlanks.length -4].
is nothing.
myNoun
with nothing.
FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine
@revisualize output: var myStr ="FirstLine\r\SecondLine\r\ThirdLine"; // Change this line
@revisualize Okay thanks that works! :D
sharang108 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3005 | @revisualize |http://www.freecodecamp.com/revisualize
\n
\\
\r
FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine
FirstLine\nbackslashSecondLinebackslashcarriage-returnThirdLine
FirstLine\n\\SecondLinebackslashcarriage-returnThirdLine
FirstLine\n\\SecondLine\\carriage-returnThirdLine
FirstLine\n\\SecondLine\\\rThirdLine
whats wrong with my code?
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var p = 0; p < arr.length; p++) {
for (var i = 0; i < arr.length[i]; i++) {
}
arr = product * arr[i];
}
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
sharang108 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: sharang108 already gave revisualize points
p
but not using it?
var nArr = [ ["b1" , "d1"] , ["f2" , "h2"] , ["j3" , "l3"] ];
nArr[1];
?
function getIndexToIns(arr, num) {
arr = arr.sort();
for (var i = 0; i< arr.length; i++){
if (arr[i] >= num) {
return i;
}
else if (arr[i] == num) {
return i;
}
}
}
getIndexToIns([2, 5, 10], 15);
"j3"
?
@revisualize pls see what's the problem now,
function chunkArrayInGroups(arr, size) {
// Break it up.
var newArray= [];
for(var i=0; i<arr.length; i+=size){
newArray.push(arr.slice(0,size));
arr= arr.slice(size);
}
return newArray;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
function getIndexToIns(arr, num) {
arr = arr.sort();
for (var i = 0; i< arr.length; i++){
if (arr[i] >= num) {
return i;
}
else if (arr[i] == num) {
return i;
}
}
}
getIndexToIns([2, 5, 10], 15);
.sort()
nArr[2]
?
@dsillydude Yes it does.
@dsillydude
var nArr = [ ["b1" , "d1"] , ["f2" , "h2"] , ["j3" , "l3"] ];
pls see what's the problem now,
function chunkArrayInGroups(arr, size) {
// Break it up.
var newArray= [];
for(var i=0; i<arr.length; i+=size){
newArray.push(arr.slice(0,size));
arr= arr.slice(size);
}
return newArray;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
function nextInLine(arr, item) {
arr.push(item);
arr.unshift();// Your code here
return arr[0]; // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr[4], 10)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
arr.unshift()
?
.unshift()
is like .push()
, to the front.
@dsillydude
var nArr = [ ["b1" , "d1"] , ["f2" , "h2"] , ["j3" , "l3"] ];
How do you access "j3"
?
richafig sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 3831 | @manish-giri |http://www.freecodecamp.com/manish-giri
How do you add a number (item
) to the end of an array (arr
)? What does this method return?
How do you remove the first element from an array (arr
)? What does this method return?
The push()
method adds one or more elements to the end of an array and returns the new length of the array.
The pop()
method removes the last element from an array and returns that element.
The shift()
method removes the first element from an array and returns that element.
The unshift()
method adds one or more elements to the beginning of an array and returns the new length of the array.
grantknaver sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3006 | @revisualize |http://www.freecodecamp.com/revisualize
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
myObj.hasOwnProperty(chechProp);
}
// Test your code by modifying these values
checkObj("gift");
var elements = document.getElementsByTagName('li');
console.log("before click");
console.log(elements);
pullData();
var arr = [].slice.call(elements);
console.log(arr);
@Manish-Giri
i<=arr.length;
function getIndexToIns(arr, num) {
arr = arr.sort(function (a, b) {
return a-b;
});
for (var i = 0; i< arr.length; i++){
if (arr[i] >= num) {
return i;
}
}
}
getIndexToIns([2, 5, 10], 15);
elements
being returned correctly?
arr[i]
's are greater than num
? Maybe you should check if num
is greater than arr[i]
and use a variable to get the index instead of returning in the for loop
ammy3165 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3007 | @revisualize |http://www.freecodecamp.com/revisualize
Second line
is not the same as SecondLine
Third Line
is not the same as ThirdLine
ammy3165 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: ammy3165 already gave revisualize points
arr
action="query"
is the best way to go?
@tiffanymakes you can still use form-submit if you fix this
prevent the default behavior
arr
as your i
variable counts up.
i
and size
in your .slice()
newArray.push(arr.slice(i,i+size));
\n
\\
\r
FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine
FirstLine\nbackslashSecondLinebackslashcarriage-returnThirdLine
FirstLine\n\\SecondLinebackslashcarriage-returnThirdLine
FirstLine\n\\SecondLine\\carriage-returnThirdLine
FirstLine\n\\SecondLine\\\rThirdLine
tiffanymakes sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1837 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
coolcoder007 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: coolcoder007 already gave revisualize points
newArray.push(arr.slice(i,i+size)); I did this too @revisualize But didn't worked.
function chunkArrayInGroups(arr, size) {
// Break it up.
var newArray= [];
for(var i=0; i<=arr.length; i+=size){
newArray.push(arr.slice(i,i+size));
arr= arr.slice(size);
}
return newArray;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
i
<=
should be <
ammy3165 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: ammy3165 already gave revisualize points
okk I was doing one more iteration, but now I have this one, still confusing;function chunkArrayInGroups(arr, size) {
// Break it up.
var newArray= [];
for(var i=0; i<arr.length; i+=size){
newArray.push(arr.slice(i,i+size));
arr= arr.slice(size);
}
return newArray;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
function convertCF(num, scale){
if (scale === "c") {
return (num - 32) * 5 / 9;
} else if (scale === "f") {
return (num * 9/5) + 32
} else if (scale !== "c" && scale !== "f"){
throw Error;
} else {
return (num - 32) * 5 / 9;
}
}
scale
(the second) argument was passed in, as I was saying.
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh",
};
function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty("checkProp")); {
return myObj[checkProp]; }
return "Not Found" ; }
// Test your code by modifying these values
checkObj("gift");
arguments
object
tiffanymakes sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 3832 | @manish-giri |http://www.freecodecamp.com/manish-giri
devlikesramen sends brownie points to @briancodes33 :sparkles: :thumbsup: :sparkles:
:cookie: 29 | @briancodes33 |http://www.freecodecamp.com/briancodes33
holler back!
@Mac33d You're escaping a carriage-return before the backslash.
@Mac33d Fix your order:
SecondLinebackslashcarriage-return
\\\
?
convertCF(50)
and you wrongly get the error
function convertCF(num, scale = "c") {
if (scale === "c") return (num - 32) / 9 * 5
if (scale === "f") return num / 5 * 9 + 32
throw new Error()
}
function convertCF(degree, scale) {
if (scale == "f") {
return degree * 9/5 + 32;
}
if (scale == "c") {
return (degree - 32) * 5/9;
}
return undefined;
}
undefined
isn't an option, probably.
// Setup
function phoneticLookup(val) {
var result = "";
// Only change code below this line
val={
"alpha":result="Adams" ,
"bravo":result="Boston",
"charlie":result="Chicago",
"delta":result="Denver",
"echo":result="Easy",
"foxtrot":result="Frank"
};
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup("charlie");
val
with an object.
lookup
as per the instructions.
result
to ""
. You are not modifying result
and your function is returning result
. Ergo, you're returning ""
. You need to modify result
to be the value of the property from the object that you created.
Time: 467ms Passed: 45 Failed: 0
You have passed all tests! :)
licheeliu sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3008 | @revisualize |http://www.freecodecamp.com/revisualize
Time: 323ms Passed: 45 Failed: 0
@revisualize still don't know what should I do with the "result"?
var lookup={
"alpha":"Adams" ,
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank"
};
function convertCF(num, scale="c"){
//code here
if (scale === "c") {
return (num - 32) * 5 / 9;
} else if (scale === "f") {
return (num * 9/5) + 32
} else {
//console.log("ERROR");
throw Error;
}
}
@Mac33d If you went word by word and got this:
var myStr ="FirstLine\n\SecondLine\rThirdLine";
You didn't go word by word.
@LicheeLiu heres my completed code
// 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",
"": undefined
};
result = lookup[val];
// Only change code above this line
return result;
}
// Change this value to test
phoneticLookup("charlie");
Write a function called "transformEmployeeData" that transforms some employee data from one format to another.
The argument will look something like this:
[
[
['firstName', 'Joe'], ['lastName', 'Blow'], ['age', 42], ['role', 'clerk']
],
[
['firstName', 'Mary'], ['lastName', 'Jenkins'], ['age', 36], ['role', 'manager']
]
]
Given that input, the return value should look like this:
[
{firstName: 'Joe', lastName: 'Blow', age: 42, role: 'clerk'},
{firstName: 'Mary', lastName: 'Jenkins', age: 36, role: 'manager'}
]
Note that the input may have a different number of rows or different keys than the given sample.
For example, let's say the HR department adds a "tshirtSize" field to each employee record. Your code should flexibly accommodate that.
Starter Code :
function transformEmployeeData(array) {
// your code here
}
function transformEmployeeData(array){
var x = {}
for(var i =0; i<data.length; i++){
x[i]=data[i];
console.log(x)
}
}
transformEmployeeData(data)
for(var i =0; i<data.length; i++)
data
?
mac33d sends brownie points to @joseph :sparkles: :thumbsup: :sparkles:
:cookie: 40 | @joseph |http://www.freecodecamp.com/joseph
Hi.... I am not able to understand why this code does not push the input values 2,3 and 6,7 into the 2D array. Here's the code below:
function chunkArrayInGroups(arr, size) {
var arrGrouped = [];
for (var i = 0; i < arr.length; i+=2) {
arrGrouped.push(arr.slice(i,i+=size));
}
return arrGrouped;
}
chunkArrayInGroups([0,1,2,3,4,5,6,7,8], 2);
i+=size
but why i+=2
?
muzaffarhssn5 sends brownie points to @masd925 and @vizij :sparkles: :thumbsup: :sparkles:
:cookie: 312 | @vizij |http://www.freecodecamp.com/vizij
i+=size
in the for loop definition and use arguments (i,i+size)
on the slice.
:star2: 3175 | @masd925 |http://www.freecodecamp.com/masd925
:bulb: to format code use backticks! ``` more info
var count=0;
Number.isNaN()
?
Counting Cards
How to do this??Can someone teach me ,please
Why is not pushing? :@@
function whatIsInAName(collection, source) {
var arr = [],b;
for (var i=0;i<collection.lenght;i++){
if(collection[i].last===source.last){
arr.push(collection[i]);
}
}
return arr;
}
whatIsInAName(
[{ first: "Romeo", last: "Montague" },
{ first: "Mercutio", last: null },
{ first: "Tybalt", last: "Capulet" }],
{ last: "Capulet" }
);
switch(card){
case 2:
case 3:
case 4:
case 5:
case 6:
count += 1;
break;
case 7:
case 8:
case 9:
count += 0;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count -= 1;
break;
}
if(count > 0){
return count + " Bet";
}
else if(count <= 0){
return count + " Hold";
}