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.
Hey guys, I am really struggling with Lesson 217 Javascript Profile Lookup. Profile Lookup
We have an array of objects representing different people in our contacts lists.
A lookUpProfile function that takes firstName and a property (prop) as arguments has been pre-written for you.
The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.
If both are true, then return the "value" of that property.
If firstName does not correspond to any contacts then return "No such contact"
If prop does not correspond to any valid properties then return "No such property"
t know how it
s work
JSON.stringify
do something?
waynebunch sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 649 | @lumexralph |http://www.freecodecamp.com/lumexralph
arr
is an array push(item)
is a method that puts the the value as the last element of an array, item is added to array arr
...... shift()
is also a method of an array that removes the first element of array arr
and returns it
prop
is a variable you can't use dot method use [ ]
way3edgyentertainment sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
inagreen sends brownie points to @way3edgyentertainment :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for way3edgyentertainment
arr
becomes [2, 3]
kulagowskim sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 650 | @lumexralph |http://www.freecodecamp.com/lumexralph
kmcrayton7 sends brownie points to @nuoz :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for nuoz
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty("checkProp")=== true);{
return myObj[checkProp];
}
else {
return "Not Found";
}
}
// Test your code by modifying these values
checkObj("house");
checkProp
is a variable not a string
"This Is A Test".match(/( [A-Z])|(^[A-Z])/g)
function caseInSwitch(val) {
var answer = "";
switch (val) {
case 1 :
console.log("alpha");
break;
case 2 :
console.log("beta");
break;
case 3 :
console.log("gamma");
break;
case 4 :
console.log("delta");
break;
}
return answer;
}
caseInSwitch(1);
return answer;
at the end - you need to set answer to the string value
if (myObj.hasOwnProperty("checkProp")=== true);{
remove the semicolon here.
checkProp
a variable there and === true
is not needed @kenbbetter
// Setup
var myStr = "Jello World";
// Only change code below this line
myStr = "Hello World";
myStr[0] = "Hello World"; // Fix Me
myStr[0]
that line causesanswer = "alpha"
ditto for the remaining cases
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Her
if (myObj.hasOwnProperty("checkProp"));
return myObj[checkProp];
}
// Test your code by modifying these values
checkObj("pet");
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Her
if (myObj.hasOwnProperty("checkProp"));
return myObj[checkProp];
}
// Test your code by modifying these values
checkObj("pet");
andercodder sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5169 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
=== true
but do not how to put the "Not found" into
var answer = '' ";
kmcrayton7 sends brownie points to @lumexralph and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:cookie: 651 | @lumexralph |http://www.freecodecamp.com/lumexralph
:star2: 5170 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
checkProp
in hasOwnProperty function should be a variable not string and remove the ;
var myObj = {
top: "hat",
bottom: "pants"
};
myObj.hasOwnProperty("top"); // true
myObj.hasOwnProperty("middle"); // false
return "Not Found";
in an else or simply after the return you hvae
top
not top?
``top ``
checkProp
from your function
checkProp
not "checkProp"
var myObj = {
top: "hat",
bottom: "pants"
};
var topvar = "top"
myObj.hasOwnProperty("top"); // true
myObj.hasOwnProperty(topvar); // true
myObj.hasOwnProperty("middle"); // false
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Her
if (myObj.hasOwnProperty(checkProp));
return myObj[checkProp];
else {
return "Not Found";
}
}
// Test your code by modifying these values
checkObj("pet");
function lookUpProfile(firstName, prop){
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{
return "No such contact";
}
}
}
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Her
if (myObj.hasOwnProperty(checkProp));
return myObj[checkProp]
else
return "Not Found";
}
// Test your code by modifying these values
checkObj("gift");
kenbbetter sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5171 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
kenbbetter sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 652 | @lumexralph |http://www.freecodecamp.com/lumexralph
way3edgyentertainment sends brownie points to @sjames1958gm and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 5172 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 3044 | @chrono79 |http://www.freecodecamp.com/chrono79
function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
fahrenheit =9/5+32 celsius ;
// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(30);
9/5+32 celsius
this is not valid syntax and doesn't match the formula C * 9/5 + 32
"I am a\"double quoted\" string inside of \"double quotes\"."; /
:warning: could not find receiver for rusdie
johnnybizzel sends brownie points to @rusdie and @jluboff :sparkles: :thumbsup: :sparkles:
:cookie: 565 | @jluboff |http://www.freecodecamp.com/jluboff
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("cat", "little", "hit", "slowly");
num
? ... var num = 7;
var favoriteAnimal = "Horse";
console.log("My favorite animal: “ + favoriteAnimal);
var favoriteAnimal = "Horse";
console.log("My favorite animal: " , favoriteAnimal);
We can use the + operator from earlier to interpolate (insert) a variable into a string, like this:
var myPet = 'armadillo';
console.log('I own a pet ' + myPet + '.');
// Output: 'I own a pet armadillo.’
itsthomas sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:cookie: 566 | @jluboff |http://www.freecodecamp.com/jluboff
function translatePigLatin(str) {
var vowels = /[aeiou]/g;
if(str[0].match(vowels).length > 0){
var arr = str.split("");
var newArr = arr.push("w", "a", "y");
return arr.join("");
}else{
return true;
}
}
translatePigLatin("eight");
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
result = + myNoun + " " +myAdjective + " " + myVerb + " " + myAdverb + " ";
// Your code above this line
return result;
}
// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
result = +
isn't correct.
// Setup
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
// Only change code below this line
var gloveBoxContents = myStorage.car["inside"].glove box; // Change this line
johnnybizzel sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2837 | @revisualize |http://www.freecodecamp.com/revisualize
"glove box"
has a space in it.
myStorage.car["inside"].glove box;
"glove"
property
js
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
myObj.hasOwnProperty(checkProp);
return "Change Me!";
}
// Test your code by modifying these values
checkObj("gift");
onSubmit
event handler is working? here is the JSFiddle link: https://jsfiddle.net/fvst3kgj/onSubmit
in <form>
.<input type ="submit">
and another is <button>SB</button>
.hasOwnProperty()
outputs a boolean. Do you know what a boolean value is?
@RhinoTek
@RhinoTek use an if
rusdie sends brownie points to @revisualize and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 3045 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 2838 | @revisualize |http://www.freecodecamp.com/revisualize
["glove box"]
greedylan sends brownie points to @revisualize and @jluboff :sparkles: :thumbsup: :sparkles:
:cookie: 567 | @jluboff |http://www.freecodecamp.com/jluboff
:star2: 2839 | @revisualize |http://www.freecodecamp.com/revisualize
var gloveBoxContents = myStorage.car.inside.["glove box"]; // Change this line
[" "]
kenbbetter sends brownie points to @chrono79 and @revisualize and @johnnybizzel :sparkles: :thumbsup: :sparkles:
:star2: 1092 | @johnnybizzel |http://www.freecodecamp.com/johnnybizzel
:star2: 3046 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 2840 | @revisualize |http://www.freecodecamp.com/revisualize
[" "]
var myVar = 87;
// Only change code below this line
var My = varyes + 1;
varyes= 87; does anyone kknow why the increment ++ of that is not working, thanks!
@avogadromert
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 (=
)?
avogadromert sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2841 | @revisualize |http://www.freecodecamp.com/revisualize
// Example
function ourFunctionWithArgs(a, b) {
console.log(a - b);
}
ourFunctionWithArgs(10, 5); // Outputs 5
// Only change code below this line.
function functionWithArgs(a, b) {
console.log("a + b");
}
functionWithArgs(1,2);
functionWithArgs(7,9);
the check points mention those numbers so that is why i put them there but I really have no idea where those numbers specifically came from
neozane1 sends brownie points to @kelechichinaka :sparkles: :thumbsup: :sparkles:
:cookie: 270 | @kelechichinaka |http://www.freecodecamp.com/kelechichinaka
saralee233 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 3047 | @chrono79 |http://www.freecodecamp.com/chrono79
ok heres the problem function multiplyAll(arr) {
var product = 1;
// Only change code below this line
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
so i did this 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.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]]);
j<arr.length
is following the correct way to create a Regexp for consonant? english letters only but without vowels
var consonant = /a-z&&[^aeiou]/
@Chrono79 how do we do it ?
neozane1 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 3048 | @chrono79 |http://www.freecodecamp.com/chrono79
how do i assign 5 to oopsGlobal with out using the var ```
// Declare your variable here
var myGlobal = 10;
function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal(5);
}
// 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);
}
// test regex for Vowel:
var patt = /A|a|E|e|I|i|O|o|U|u/;
// Declare your variable here
var myGlobal = 10;
function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal(5);
}
// 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);
}
neozane1 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: neozane1 already gave chrono79 points
"My " + myAdjective + " " + myNoun
results in "My big dog"
scoutsnknives sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 1009 | @margaret2 |http://www.freecodecamp.com/margaret2
greedylan sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 3049 | @chrono79 |http://www.freecodecamp.com/chrono79
xcbyers sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 3050 | @chrono79 |http://www.freecodecamp.com/chrono79
keewhy sends brownie points to @byzgig :sparkles: :thumbsup: :sparkles:
:cookie: 387 | @byzgig |http://www.freecodecamp.com/byzgig
doodleslr sends brownie points to @eeflores :sparkles: :thumbsup: :sparkles:
:cookie: 896 | @eeflores |http://www.freecodecamp.com/eeflores
function isLess(a, b) {
// Fix this code
switch (a==b)
{
case a<b :
return false;
case b<a :
return true;
}
}
// Change these values to test
isLess(10, 15);
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
> is greater than and === is equal to
+=
to +
myStr += "secondSentence";
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.length[i]; j++){
console.log(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]]);
@HeebieGeeBee
// Declarations
var studlyCapvar = 10;
var properCamelcase = "A String";
var titleCaseover = 9000;
// Assignments
studlyCapvar = 10;
properCamelcase = "A String";
titleCaseover = 9000;
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
result = myNoun+ " " +myAdjective+ " " +myVerb+ " " +myAdverb+ " ";
// Your code above this line
return result;
}
// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
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.length[i]; j++){
product.push(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
is a number, you can't use .push()
on a number. But you're close.
.push()
, you need to multiply product
with the current number in the nested loop
_____* arr[i][j]
;
cesarecaravaggio sends brownie points to @revisualize and @cburros :sparkles: :thumbsup: :sparkles:
:cookie: 285 | @cburros |http://www.freecodecamp.com/cburros
:star2: 2843 | @revisualize |http://www.freecodecamp.com/revisualize
product*arr[i][j]
is an expression, it returns a number
product
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.length[i]; j++){
product*arr[i][j];
}
}
cburros sends brownie points to @cesarecaravaggio :sparkles: :thumbsup: :sparkles:
:cookie: 99 | @cesarecaravaggio |http://www.freecodecamp.com/cesarecaravaggio
store the result back in product
product = product * arr[i][j];
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.length[i]; j++){
product = 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]]);
still returning "1"
j<arr.length[i]
length
of arr[i]
johnnunns sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 3559 | @manish-giri |http://www.freecodecamp.com/manish-giri
//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
if(contacts.firstName === true &&contacts.prop === true){
return contacts;
} else if( contacts.firstName===false){
return "No such contact";
} else {
return "No such property";
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "likes");
name = 'Ben';
contacts
is an array
var contacts = [ "A" , "H" , "S" , "K" ];
"H"
?
@johnnunns Let's say you have an object.
// var name = "Happy";
var myFriend = {
"firstName": "Happy",
"lastName": "Feet",
"number": "-i",
"likes": ["rhythm", "dancing", "soul"]
}
How do you access the firstName of myFriend?
function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch(val){
case 1:
if(val=="a"){
return "apple";
}break;
case 2:
if(val=="b"){
return "bird";
}break;
case 3:
if(val=="c"){
return "cat";
}break;
default:
if(val== "d"){
return "stuff";
}
}
// Only change code above this line
return answer;
}
// Change this value to test
switchOfStuff(a);
switch
/case
@johnnunns Let's say we have an array:
var contacts = [ { f: "A" } , { f: "H" } , { f: "S" } , { f: "K" } ];
How do you output "H"
?
Accessing Nested Objects .... What am I missing here?
// Setup
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
// Only change code below this line
var gloveBoxContents = "myStorage.car.inside["glove box"]"; // Change this line
{ f: "H" }
function largestOfFour(arr) {
var result = [];
var value = 0;
for(var i=0;i<=arr.length;i++) {
for(var j=0;j<=arr.length;j++) {
if(arr[i][j]>value){
value = arr[i][j];
}
result.push(value);
}
}
return result;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
@johnnunns Let's say you have an object.
// var name = "Happy";
var myFriend = {
"firstName": "Happy",
"lastName": "Feet",
"number": "-i",
"likes": ["rhythm", "dancing", "soul"]
}
How do you access the firstName of myFriend?
@johnnunns
Let's say we have an array:var contacts = [ "A" , "H" , "S" , "K" ];
How do you access "H"
?
Let's say we have an array:
var contacts = [ { f: "A" } , { f: "H" } , { f: "S" } , { f: "K" } ];
How do you output "H"
?
:bulb: to format code use backticks! ``` more info
f:
was firstName:
?
[1]
???
@johnnunns Then I'm going to ask...
What iff:
wasfirstName:
?
:bulb: to format code use backticks! ``` more info
:bulb: to format code use backticks! ``` more info
can someone give me a simpler explanation for this por favor?
var arr = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
];
arr[3]; // equals [[10,11,12], 13, 14]
arr[3][0]; // equals [10,11,12]
arr[3][0][1]; // equals 11
how does that work???
:bulb: to format code use backticks! ``` more info
hello
cesarecaravaggio sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: cesarecaravaggio already gave revisualize points
//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
if(contacts.firstName === "" &&contacts[prop] === ""){
return contacts[prop];
} else if( contacts.firstName!==""){
return "No such contact";
} else {
return "No such property";
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "likes");
@revisualize
@cesarecaravaggio hmm.. just compare this two arrays:
arr1 = [a, b, c];
arr2 = [[X,Y,Z],[apple, banana]];
it is important to note that each element in an array are indexed starting from ZERO.
arr1[0] will return just 'b'
whereas arr2[0] will return the first element [X,Y,Z] of the main array which only consists of two elements i.e. [X,Y,Z] and [apple,banana]
therefore arr2[0][1] will check the 2nd element in array [X,Y,Z] which is just 'Y'
// Setup
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};
// Only change code below this line
var gloveBoxContents = "myStorage.car.inside["glove box"]"; // Change this line
Accessing Nested Objectsvar gloveBoxContents = "myStorage.car.inside["glove box"]";
change this to var gloveBoxContents = myStorage.car.inside["glove box"];
cesarecaravaggio sends brownie points to @tracesofnuts :sparkles: :thumbsup: :sparkles:
:cookie: 251 | @tracesofnuts |http://www.freecodecamp.com/tracesofnuts
var myVar = 87;
// Only change code below this line
myVar = 88;
var x = 1;
x = x + 1; // => x is now 2
x++; // => x is now 3
Notice how both ways end up doing the same thing… incrementing x by 1.
jayisray sends brownie points to @tracesofnuts :sparkles: :thumbsup: :sparkles:
:cookie: 252 | @tracesofnuts |http://www.freecodecamp.com/tracesofnuts
mattcharlesh sends brownie points to @tracesofnuts :sparkles: :thumbsup: :sparkles:
:cookie: 253 | @tracesofnuts |http://www.freecodecamp.com/tracesofnuts
function palindrome(str) {
forstr=str.toLowerCase();
forstr.replace(/([^\w]*)/gi,'');
strarr=forstr.split('');
strarr.reverse();
backstr=strarr.join('');
if(forstr==backstr){
return true;
}
}
//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(i=0;i<contacts.length;i++){
if(contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop) ){
return contacts[i][prop];
} else if( contacts[i].firstName!== firstName){
return "No such contact";
} else {
return "No such property";
}
// Only change code above this line
}
}
// Change these values to test your function
lookUpProfile("Akira", "likes");
str.replace(/[^0-9a-z]/gi, '')
forstr=str.replace(/[^0-9a-z]/gi, '').toLowerCase();
:cookie: 254 | @tracesofnuts |http://www.freecodecamp.com/tracesofnuts
way3edgyentertainment sends brownie points to @tracesofnuts :sparkles: :thumbsup: :sparkles:
var numInRange = 0;
var numOfRange = 0;
var accuStatus;
function sumAll(arr) {
var maxNum = Math.max.apply(null, arr), minNum = Math.min.apply(null, arr);
for(var i = minNum + 1; i < maxNum; i++){
numInRange += i;
}
arr.reduce(function(accumulator, currentValue, currentindex, array){
numOfRange = accumulator + currentValue;
});
return numInRange + numOfRange;
}
sumAll([5, 9]);
@sainiabhi unction sumAll(arr) {
var x=Math.max(arr[0] ,arr[1]);
var y=Math.min(arr[0] ,arr[1]);
var temp=0;
for(var i=y;i<=x;i++)
{
temp=temp+i;
}
return (temp);
}
sumAll([1, 4]);
sainiabhi sends brownie points to @adityavisen :sparkles: :thumbsup: :sparkles:
:cookie: 319 | @adityavisen |http://www.freecodecamp.com/adityavisen
sainiabhi sends brownie points to @tracesofnuts :sparkles: :thumbsup: :sparkles:
:cookie: 256 | @tracesofnuts |http://www.freecodecamp.com/tracesofnuts
function sumAll(arr) {
var numInRange = 0;
var maxNum = Math.max.apply(null, arr), minNum = Math.min.apply(null, arr);
for(var i = minNum; i <= maxNum; i++){
numInRange += i;
}
return numInRange;
}
sumAll([5, 9]);
//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(i=0;i<contacts.length;i++){
if(contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop) ){
return contacts[i][prop];
}
}
if( contacts.firstName!== firstName){
return "No such contact";
} else (contacts.prop!==prop){
return "No such property";
// Only change code above this line
}
}
// Change these values to test your function
lookUpProfile("Harry", "likes");
function largestOfFour(arr) {
// You can do this!
var maxNum;
for(i=0; i<i.length(); i++)
manNum = Math.max(...arr[i]);
return maxNum;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
@carpben hmm maybe its the
...
how bout trying
manNum = Math.max(arr[i]);
johnnunns sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2844 | @revisualize |http://www.freecodecamp.com/revisualize
FirstLine
\SecondLine\
ThirdLine
@grandmasterundead Third Line is not the same as ThirdLine
\r
not after to it
\\
before and after SecondLine
Math.max
uses numbers as arguments but you're using array instead
grandmasterundead sends brownie points to @revisualize and @ghulamshabir :sparkles: :thumbsup: :sparkles:
:star2: 2845 | @revisualize |http://www.freecodecamp.com/revisualize
:star2: 1621 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
// Setup
var myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];
// Only change code below this line
var secondTree = myPlants[1].list["1"]; // Change this line
Accessing Nested Arrays ...What did i miss?
function largestOfFour(arr) {
var i,j,newArr=[];
newArr.length = arr.length;
for (i = 0; i<arr.length; i++) {
newArr[i] = 0;
for (j = 0; j<arr[i].length; j++) {
if (arr[i][j]>newArr[i]) {
newArr[i]=arr[i][j];
}
}
}
return newArr;
}
mattcharlesh sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2846 | @revisualize |http://www.freecodecamp.com/revisualize
return
statements cause functions to halt and return. If you're trying to do a return inside of a loop it will cause the function to halt and return the information that you specify.
Math.max
for that problem
newArr.length = arr.length;
doesn't do anything.
tracesofnuts sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2847 | @revisualize |http://www.freecodecamp.com/revisualize
newArr.length = arr.length;
and newArr[i] = 0;
you could have used a variable say var largest=0;
@TracesOfNuts cool. Please be aware that your comparison will not necessarily return the max number, but might return a 0 instead.
yup this is with assumption that the array consists of only positive integers.
num
? ... var num = 7;
num
+ 3 = 10 What is the value of num
?var x = num + 3;
... That outputs 10x
? ... x = 5;
(Which is also overwriting the previous value of 10 from above.x
to a variable y
?var y = x;
answer
? ... What is the answer?pls share it
@TracesOfNuts I just made another solution using the spread operator.
return
statements cause functions to halt and return. If you're trying to do a return inside of a loop it will cause the function to halt and return the information that you specify.var Car = function() {
// this is a private variable
var speed = 10;
// these are public methods
this.accelerate = function(change) {
speed += change;
};
this.decelerate = function() {
speed -= 5;
};
this.getSpeed = function() {
return speed;
};
};
var Bike = function() {
var gear =1;
this.getGear = function() {
gear = 2;
};
this.setGear = function() {
gear = 3;
};
};
var myCar = new Car();
var myBike = new Bike();
myBike.getGear();
myBike.setGear();
var Car = function() {
// this is a private variable
var speed = 10;
// these are public methods
this.accelerate = function(change) {
speed += change;
};
this.decelerate = function() {
speed -= 5;
};
this.getSpeed = function() {
return speed;
};
};
var Bike = function() {
var gear =0;
this.getGear = function() {
return gear;
};
this.setGear = function() {
gear=1;
};
};
var myCar = new Car();
var myBike = new Bike();
myBike.getGear();
myBike.setGear(4);
now ??
@amarg26 setGear should take a parameter and assign that to gear and getGear should just return gear. finally gear should be initialized with 0 not with 1
var count = 0;
function cc(card) {
// Only change code below this line
var answer = "" ;
switch(card){
case 2:
case 3:
case 4:
case 5:
case 6:
answer = "Bet";
break;
case 10:
case 'J':
case 'Q':
case 'k':
case 'A':
answer = "Hold";
break;
}
return answer;
// 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
var answer = "" ;
switch(card){
case 2:
case 3:
case 4:
case 5:
case 6:
answer = "Bet";
break;
case 10:
case 'J':
case 'Q':
case 'k':
case 'A':
answer = "Hold";
break;
}
return answer;
// 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');
jainishpanchal sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:cookie: 444 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
just need to throw in
/*jshint esversion: 6 */
at the top
carpben sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2848 | @revisualize |http://www.freecodecamp.com/revisualize
=
works from right to left
```var Bike = function() {
var gear =0;
this.getGear = function() {
return gear;
};
this.setGear = function() {
return gear;
};
};
var myCar = new Car();
var myBike = new Bike();
myBike.getGear();
gear=myBike.setGear(gear);
```
:star2: 1622 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
official4code sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
rsteen76 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 2849 | @revisualize |http://www.freecodecamp.com/revisualize
function f(param) {
someVar = param;
}
\
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
{
"artist": "Joel",
"title": " Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
// Add record here
];
@jainishpanchal
'your string can have double" quotes " in it`
something like that
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));
@ghulamshabir this is the code i have done
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
{
"artist": "Joel",
"title": " Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
// Add record here
];
[{...}, {...}]
item
to the end of arr
then remove and return first element. you will need two array methods. previous lessons titles Manipulating Arrays with... might be helpful
:star2: 1623 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
donswavey sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
uxsasukexnaruto sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
:star2: 1624 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
function lookUpProfile(firstName, prop){
// Only change code below this line
for (i=0;i<contacts.length;i++){
if (contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];}
else if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop) !== true){
return "No such property";}
else if (contacts[i].firstName !== firstName) {return "No such contact";}
}
// Only change code above this line
}
function lookUpProfile(firstName, prop){
// Only change code below this line
for (i=0;i<contacts.length;i++){
if (contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];}
else if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop) !== true){
return "No such property";}
else if (contacts[i].firstName !== firstName) {return "No such contact";}
}
// Only change code above this line
}
@uxsasukexnaruto :smile:
@official4code
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 (=
)?
rahul-thakoor sends brownie points to @maestat :sparkles: :thumbsup: :sparkles:
:cookie: 266 | @maestat |http://www.freecodecamp.com/maestat
function chunkArrayInGroups(arr, size) {
// Break it up.
var newArr = [];
for(var i = 0; i < arr.length; i += size) {
newArr.push(arr.slice(0, size));
console.log(newArr);
arr = arr.slice(size, -1);
console.log(arr);
}
return arr;
}
chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4);
newArr.push(arr.slice(0, size));
just adjust the slice arguments to get you right chunks of the array
Hey, can you help me out with this code: var myStr= "Firstline"\n \"SecondLine"\ \r"ThirdLine";
I'm supposed to make it look like:
FirstLine
\SecondLine\
ThirdLine
@ghulamshabir
var myStr= FirstLine \n \ SecondLine \ \r ThirdLine;
or
FirstLine\n\SecondLin\\rThirdLine;
It still doesn't work
Error Statement: myStr should have encoded text with the proper escape sequences and no spacing.
dhwani24 sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
:star2: 1625 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
[ '1', 'vasya', '2', 'petya', '3', 'kolya', '4', 'limak', '5', 'illya' ]
for(var i = 0; i<inputHash.length; i+2){
h[inputHash[i]]= inputHash[i+1];
}
for(var i = 0; i<inputHash.length-1; i++){
h[i]= inputHash[i+1];
}
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][prop]){return contacts[i][prop]; }else {return "No such Property";}}
else {return "No such contact";}}
// Only change code above this line
}
ser Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.
My code:
// Setup
var a;
var b = 2;
// Only change code below this line
b = a = 7;
// Only change code below this line
a = 7;
b = a;
cafam sends brownie points to @jmbravo :sparkles: :thumbsup: :sparkles:
:cookie: 173 | @jmbravo |http://www.freecodecamp.com/jmbravo
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));
@jmbravo // Example
var ourVar = 19;
// Only change code below this line
var myVar = 9;
item
to the end of arr
them remove and return first element. you will need two array methods for this. the previous lessons titled Manipulating Arrays with... might be helpful
jmbravo sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
:star2: 1626 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
@jmbravo Initializing Variables with the Assignment Operator
It is common to initialize a variable to an initial value in the same line as it is declared.
var myVar = 0;
Creates a new variable called myVar and assigns it an initial value of 0.
Instructions
Define a variable a with var and initialize it to a value of 9.
// Only change code below this line
var a = 9;
@ghulamshabir i'm using this code :
function reverseString(str) {
var tes = "";
for (var i=str.length-1;i>=0;i--) {
tes += str[i];
}
return tes;
}
reverseString("hello");
mahdiarn sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
:star2: 1627 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
\\
for a backslash
""
you need \n \\ \r
\\
before and after SecondLine
daahel sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
:star2: 1628 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
daahel sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 653 | @lumexralph |http://www.freecodecamp.com/lumexralph
```var Bike = function() {
var gear =0;
this.getGear = function() {
return gear;
};
function setGear(gear) {
var g1= gear;
}
};
var myCar = new Car();
var myBike = new Bike();
myBike.getGear();
g1=myBike.setGear(gear);
```
TypeError:myBike .setGear is not a function
this.setGear
please fix this
```var Bike = function() {
var gear =0;
this.getGear = function() {
return gear;
};
this.setGear = function() {
var g1= gear;
};
};
var myCar = new Car();
var myBike = new Bike();
myBike.getGear();
g1=myBike.setGear(gear);```
this.setgear
doesn't have a parameter to set to gear
this.setGear = function(gear) {
var g1= gear;
};
var gear
to the parameter of this.setGear
when it's called
{ var g1= gear; }
should be { gear = parameter from the setGear method; }
amarg26 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 654 | @lumexralph |http://www.freecodecamp.com/lumexralph
function mutation(arr) {
var firstWord = arr[0].toLowerCase();
var secondWord = arr[1].toLowerCase();
for ( var i = 0; i < secondWord.length; i++ ){
if (firstWord.indexOf(secondWord[i]) >= 0){
return true;
}
else return false;
}
}
mutation(["Alien", "line"]);
sennator2 sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
:star2: 1629 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
@egbuna
https://