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.
total = 2+5;
%
+
adition operator total = 2 + 5
/
division operator total = 2 / 5
*
multiplication operator... total = 2 * 5
%
crazymaster49 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 2015 | @moigithub |http://www.freecodecamp.com/moigithub
@hippybearfunction orderMyLogic(val) {
if (val < 10) {
return "Less than 10";
} else if (val < 5) {
return "Less than 5";
} else {
return "Greater than or equal to 10";
}
}
// Change this value to test
orderMyLogic(9);
arguments
is an array of arguments used to execute the function, you're just passing it on synthetically
arguments
array isn't really an array, so it doesn't conform to the standard Array protocol)
.reduce
or forEach
(IIRC)
> var realArray = []
undefined
> var fakeArray
undefined
> function setFake() { fakeArray = arguments }
undefined
> setFake()
undefined
> realArray instanceof Array
true
> fakeArray instanceof Array
false
function pairwise(arr, arg) {
var job = [];
var select = false;
var test = arr;
// console.log(test);
for(var i = 0; i < arr.length; i++){
select = false;
for(var j = 0; j < arr.length; j++){
if(arr[i] + arr[j] === arg){
job.push({one: arr.indexOf(arr[i]), two: arr.indexOf(arr[j])});
arr[i] = false;
arr[j] = false;
}
}
console.log(arr);
console.log(job);
}
//console.log(arr);
return job.reduce(function(a, b){
return a + b;
});
}
pairwise([1, 3, 2, 4], 4);
var arguments = { 0: 'firstArg', 1: 'SecondArg' }
var arguments = ['firstArg', 'SecondArg']
.apply()
:> function greeting(firstName, lastName) { console.log('Hello, ' + firstName + ' ' + lastName + '!') }
undefined
> greeting('John', 'Doe')
Hello, John Doe!
undefined
> greeting.apply({}, ['John', 'Doe'])
Hello, John Doe!
undefined
>
brianrudloff sends brownie points to @egoscio :sparkles: :thumbsup: :sparkles:
:warning: brianrudloff already gave egoscio points
function largestOfFour(arr) {
var finalarr = [];
for (var i = 0; i < arr.length; i++) {
finalarr.push(Math.max.apply(Math, i));
}
return finalarr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
function largestOfFour(arr) {
var finalarr = [];
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr.length; j++) {
finalarr.push(Math.max.apply(Math, j));
}
}
return finalarr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
arr.indexOf(arr[i])
will return the same value of i
.. also the other one.. will return j
valuearr[0] + arr[0]
--->>> if(arr[i] + arr[j] === arg){
function largestOfFour(arr) {
var finalarr = [];
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j[i] < arr.length; j++) {
finalarr.push(Math.max.apply(Math, j[i]));
}
}
return finalarr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j[i] < arr.length; j++) {
j
cuz j[i]
is wrong
j
have a 0
valuei
have also 0 value ur code doing 0[0]
<---is that correct ??missing letters
if(arr[i] + arr[j] === arg && i!==j){ // compare if i is different than j.. so u not do arr[0] + arr[0]
job.push({one: i, two: j)});
order matters... @CageEcharte
(async ) code run from top to bottom... and only 1 of the if /elseif blocks gets executed
soo knowing that ....
if val is 4.. what if block gets executed ????
@moigithubfunction orderMyLogic(val) {
if (val < 4) {
return "Less than 10";
} else if (val < 6) {
return "Less than 5";
} else {
return "Greater than or equal to 10";
}
}
// Change this value to test
orderMyLogic(7);
function orderMyLogic(val) {
if (val < 10) {
return "Less than 10"; // first block
} else if (val < 5) {
return "Less than 5"; // second block
} else {
return "Greater than or equal to 10"; // third block
}
}
// Change this value to test
orderMyLogic(9);
orderMyLogic( 4 );
<--- i said.. IF val
is 4.. what ur code will do ??
if (val < 10) {
--->>> if (4 < 10) {
and ask ur self.. is 4 less than 10 ?? is true or false???function orderMyLogic(val) {
<--- THAT val.. ur argument variable nameorderMyLogic( 4 );
what do u think willl be the value of val
byzgig sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 2016 | @moigithub |http://www.freecodecamp.com/moigithub
function titleCase(str) {
str = str.toLowerCase();
var newStr = str.split(' ');
for(var i=0; i<newStr.length;i++){
newStr[i][0] = newStr[i][0].toUpperCase();
}
str = newStr.join(' ');
return str;
}
titleCase("I'm a little tea pot");
myStr[0]
="H" // fail
function titleCase(str) {
str = str.toLowerCase();
str = str.split(' ');
for(var i=0; i<str.length;i++){
str[i]=str[i].split('');
str[i][0] = str[i][0].toUpperCase();
str[i]=str[i].join('');
}
return str.join(' ');
}
titleCase("I'm a little tea pot");
function orderMyLogic(val) {
if (val < 10) {
return "Less than 10";
} else if (val < 5) {
return "Less than 5";
} else {
return "Greater than or equal to 10";
}
}
// Change this value to test
orderMyLogic(7);
how do I get the codes to put out less then 5?
str[i] = str[i][0].toUpperCase()+str[i].slice(1);
@Symbolistic
format
I'm having trouble figuring this out .......function orderMyLogic(val) {
if (val < 10) {
return "Less than 10";
} else if (val < 5) {
return "Less than 5";
} else {
return "Greater than or equal to 10";
}
}
// Change this value to test
orderMyLogic(7);
console.log('hello world');
function orderMyLogic(val) {
if (val < 10) {
return "Less than 10";
} else if (val < 5) {
return "Less than 5";
} else {
return "Greater than or equal to 10";
}
}
// Change this value to test
orderMyLogic(7);
val
is 3?
@CageEcharte put three backticks before and after your code to format it into a codeblock, like so:console.log('hello world');
1
key
I am stuck in this any help please? what I am doing wrong???``````
var count = 0;
function cc(card) {
// Only change code below this line
if (card === 10 || card === "J" || card === "Q" || card === "K" || card === "A") {
count--;
return (count +" Hold");
}
else if (card === 7 || card === 8 || card === 9) {
return (count +" Hold");
}
else if (card === 2 || card === 3 || card === 4 || card === 5 || card === 6) {
count++;
return (count + " Bet");
}
else if (count > 0) {
return (count + " Bet");
}
else if (count <= 0) {
return (count + " Hold");
}
// 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');```
mine is on ~ key :smile:
shift+\`` = ~
, generally speaking.
cageecharte sends brownie points to @johnngo :sparkles: :thumbsup: :sparkles:
:cookie: 179 | @johnngo |http://www.freecodecamp.com/johnngo
```function orderMyLogic(val) {
if (val < 5) {
return "Less than 5";
} else if (val < 10) {
return "Less than 10";
} else {
return "Greater than or equal to 10";
}
}
// Change this value to test
orderMyLogic(7);```
purelight4ever sends brownie points to @redmega :sparkles: :thumbsup: :sparkles:
:cookie: 102 | @redmega |http://www.freecodecamp.com/redmega
test
test4
americanpi sends brownie points to @redmega :sparkles: :thumbsup: :sparkles:
:cookie: 103 | @redmega |http://www.freecodecamp.com/redmega
test
so "ctr+/" bring up compose mode where you can type
multiple lines
like this
test
:bulb: to format code use backticks! ``` more info
:bulb: to format code use backticks! ``` more info
joufflu sends brownie points to @tbushman :sparkles: :thumbsup: :sparkles:
:cookie: 138 | @tbushman |http://www.freecodecamp.com/tbushman
@Chrono79 here is my code ````
function caseInSwitch(val) {
var answer = "";
// Only change code below this line
val = 1;
console.log("alpha");
break;
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(1);
```
switch
's
switch (num) {
case value1:
statement1;
break;
case value2:
statement2;
break;
...
case valueN:
statementN;
break;
}
function updateRecords(id, prop, value) {
if(collection.hasOwnProperty(id)){
if (prop == "tracks"){
if (value === "" && collection[id].hasOwnProperty(prop)){
collection[id][prop].push(value);
}else if(value === "" && collection[id].hasOwnProperty(prop) === false){
collection[id][prop]= [value];
}else{
delete collection[id][prop];
}
}else{
if(value === ""){
collection[id][prop] = value;
}else{
delete collection[id][prop];
}
}
}
return collection;
}
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");
function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val) {
case 1:
console.log("alpha");
break;
}
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(1);
orionishere sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1923 | @chrono79 |http://www.freecodecamp.com/chrono79
function updateRecords(id, prop, value) {
if(collection.hasOwnProperty(id)){
if (prop == "tracks"){
if (value === "" && collection[id].hasOwnProperty(prop)){
collection[id][prop].push(value); // if value is "" you should delete the property, you're not doing that here
}else if(value === "" && collection[id].hasOwnProperty(prop) === false){
collection[id][prop]= [value]; // or here
}else{
delete collection[id][prop];
}
}else{
if(value === ""){
collection[id][prop] = value; // here either
}else{
delete collection[id][prop]; //here you shouldn't delete the property
}
}
}
return collection;
}
result=myNoun + " " + myAdjective + " " +
and keep going. Be sure to put actual spaces between the quotes
purelight4ever sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1924 | @chrono79 |http://www.freecodecamp.com/chrono79
purelight4ever sends brownie points to @bibubi :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for bibubi
nicopcat sends brownie points to @coffeebeanzz and @chrono79 and @ndburrus :sparkles: :thumbsup: :sparkles:
:star2: 1010 | @coffeebeanzz |http://www.freecodecamp.com/coffeebeanzz
:star2: 1902 | @ndburrus |http://www.freecodecamp.com/ndburrus
:star2: 1925 | @chrono79 |http://www.freecodecamp.com/chrono79
i'm stuck on the Seek and Destroy challenge. I looked at all the references on MDN, w3schools , and tutorialspoint.com. can someone give me a hint?
```javascript function destroyer(element, index, array) {
return (element != arguments[1]);
}
var filtered = array.filter(destroyer);
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
```
var a = 3;
var b = 17;
var c = 12;
// Only modify code below this line
a += a + 12 ;
b += 9 + b ;
c += c + 7 ;
whats wrong with my code please help.
:bulb: to format code use backticks! ``` more info
Hello. I'm stuck on item #5 of the Profile Lookup challenge. What am I doing wrong? ```for (var i=0; i < contacts.length; i++) {
if (contacts[i].firstName == firstName)
if ( contacts[i][prop] )
return contacts[i][prop];
} //items #1-#3 work
{ return "No such contact"; } //item #4 works
if (contacts[i].hasOwnProperty(prop) === false )
return "No such property";
Math.floor(Math.random() * (max - min)) + min;
querySelector
. can anybody tell me the difference between querySelector/querySelectorAll and getElementById/getElementsByClassName? it seems like querySelector is more useful, but please let me know if I'm wrong
edmundtfy sends brownie points to @tbushman :sparkles: :thumbsup: :sparkles:
:cookie: 140 | @tbushman |http://www.freecodecamp.com/tbushman
so do
shift enter
then add
then shift enter
shift-enter gives line breaks between ```s
@tbushman I rewrote my code but it's still not working. ```for (var i=0; i < contacts.length; i++) {
if (contacts[i].firstName == firstName)
if ( contacts[i][prop] )
return contacts[i][prop];
} //items #1-#3 work
{ return "No such contact"; } //item #4 works
{
if (contacts[i][prop] === false)
return "No such property";
}
```
format
saxmanmike sends brownie points to @tbushman :sparkles: :thumbsup: :sparkles:
:cookie: 141 | @tbushman |http://www.freecodecamp.com/tbushman
for (var i=0; i < contacts.length; i++) {
if (contacts[i].firstName == firstName)
if ( contacts[i][prop] )
return contacts[i][prop];
} //items #1-#3 work
{ return "No such contact"; } //item #4 works
{
if (contacts[i][prop] === "null")
return "No such property";
}
function titleCase(str) {
var lowCase = str.toLowerCase();
var result = lowCase.replace((/\b\w/g), function(l){
return l.toUpperCase();
});
console.log(result);
return result;
}
@hacu9 you can just do
lowCase.replace(..).toUpperCase();
I think
function queue(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(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
for (var i=0; i < contacts.length; i++) {
if (contacts[i].firstName == firstName)
if ( contacts[i][prop] )
return contacts[i][prop];
} //items #1-#3 work
{ return "No such contact"; } //item #4 works
{
if (contacts[i][prop] === false) // THis , if 'null', reads 'if (null === false)'
return "No such property";
}
lowCase.replace(/\b\w/g).toUpperCase();
saxmanmike sends brownie points to @tbushman :sparkles: :thumbsup: :sparkles:
:warning: saxmanmike already gave tbushman points
natto278 sends brownie points to @tbushman :sparkles: :thumbsup: :sparkles:
:cookie: 142 | @tbushman |http://www.freecodecamp.com/tbushman
js
var myStr="Here is a backslash: \\.\n\t\tHere is a new line with two tabs.";// Cha
@Natto278 and this two, you can just do an if else instead
if ( contacts[i][prop] )
return contacts[i][prop];
}
if (contacts[i][prop] === false) // THis , if 'null', reads 'if (null === false)'
return "No such property";
}
since you are testing if the property exist. if it does return the value from the lookup else return No such property
if contact in the ith index hasOwnProperty prop
//return value from the lookup
else
//return "No such property"
js
var myStr="Here is a backslash: \\.\n\t\tHere is a new line with two tabs.";
js var myStr="Here is a backslash:\\.\n\t\tHere is a new line with two tabs.";
newlinebackslash
SecondLinebackslashcarriage-return
ThirdLineindhusethu sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1469 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
function nextInLine(arr,item){
var arr = [1,2]; //<-----------that has the same name as you function argument arr(will overwrite and cause confusion)
return item;
}
function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val) {
case "alpha" :
return answer;
break;
case "beta" :
return answer;
break;
case "gamma" :
return answer;
break;
case "delta" :
return answer;
break;
}
// Only change code above this line
return answer;
}
// Change this value to test
caseInSwitch(1);
for(var j = 0; j < boxes.length; j++){
var interval;
var outInterval;
boxes[j].addEventListener('mouseover',function(){
var percent = -0.005;
var t = this;
clearInterval(outInterval);
interval = setInterval(function(){
t.style.background = shadeColor(boxColor, percent);
if(percent >= -0.1){
percent -= 0.005;
}
}, 10);
});
boxes[j].addEventListener('mouseout',function(){
var percent = -0.1;
var t = this;
clearInterval(interval);
outInterval = setInterval(function(){
t.style.background = shadeColor(boxColor, percent);
if(percent <= 0){
percent += 0.005;
}
}, 10);
this.style.background = boxColor;
});
}
jamesmillerho sends brownie points to @damakuno :sparkles: :thumbsup: :sparkles:
:cookie: 39 | @damakuno |http://www.freecodecamp.com/damakuno
function rot13(str) {
//str = str.split('');
var rot13 = "";
for (var i = 0; i < str.length; i++){
if (90 >= str.charCodeAt(i) >= 65){
if (str.charCodeAt(i) < 78){
console.log(String.fromCharCode(str.charCodeAt(i)+13));
rot13 += String.fromCharCode(str.charCodeAt(i)+13);
} else {
var num = 90 - str.charCodeAt(i);
rot13 += String.fromCharCode(65+num);
}
} else {
rot13 += str[i];
}
}
return rot13;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
str[i].charCodeAt(0)
90 >= str.charCodeAt(i) && str.charCodeAt(i) >= 65
90 >= str.charCodeAt(i) >= 65
Here is the text with the escape sequences written out.
"FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine"
var myStr;
myStr = "Firstline\nSecondline\\\Thirdline";
// Change this line
var myStr = "FirstLine\n\\SecondLine\\\rThirdLine";
:cookie: 9 | @sandeepsafalta |http://www.freecodecamp.com/sandeepsafalta
:cookie: 401 | @jamesmillerho |http://www.freecodecamp.com/jamesmillerho
xulenvirp sends brownie points to @jamesmillerho and @sandeepsafalta :sparkles: :thumbsup: :sparkles:
'no' is not recognized as an internal or external command,
operable program or batch file.
no -offence friends
looks like a command, which means you're passing in a parameter called -offence
and then you tell it who to offend - friends
sohan2infosec sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1472 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
jamesmillerho sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1473 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
jamesmillerho sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
:cookie: 633 | @adityaparab |http://www.freecodecamp.com/adityaparab
function collisionCheck() {
/* getting all the axes from both shapes */
var axes = [];
for(var i=0; i<shape1.vertices.length; i++) {
var v1 = shape1.vertices[i];
var v2 = [];
if(i < shape1.vertices.length-1) {
v2 = shape1.vertices[i+1];
}
else {
v2 = shape1.vertices[0];
}
var edge = [v2[0]-v1[0], v2[1]-v1[1]];
var normal = [-edge[1], edge[0]];
var mag = Math.sqrt(normal[0]*normal[0] + normal[1]*normal[1]);
var unit = [normal[0]/mag, normal[1]/mag];
axes.push(unit);
}
for(var i=0; i<shape2.vertices.length; i++) {
var v1 = shape2.vertices[i];
var v2 = [];
if(i < shape2.vertices.length-1) {
v2 = shape2.vertices[i+1];
}
else {
v2 = shape2.vertices[0];
}
var edge = [v2[0]-v1[0], v2[1]-v1[1]];
var normal = [-edge[1], edge[0]];
var mag = Math.sqrt(normal[0]*normal[0] + normal[1]*normal[1]);
var unit = [normal[0]/mag, normal[1]/mag];
axes.push(unit);
}
/* projecting both shapes onto each axes */
for(var i=0; i<axes.length; i++) {
var axis = axes[i];
// projecting shape 1
var min = Infinity;
var max = -Infinity;
for(var j=0; j<shape1.vertices.length; j++) {
var vertex = shape1.vertices[j];
var proj = axis[0]*vertex[0] + axis[1]*vertex[1];
if(proj < min) {
min = proj;
}
else if(proj > max) {
max = proj;
}
}
var projection1 = [min, max];
// projecting shape 2
var min = Infinity;
var max = -Infinity;
for(var j=0; j<shape2.vertices.length; j++) {
var vertex = shape2.vertices[j];
var proj = axis[0]*vertex[0] + axis[1]*vertex[1];
if(proj < min) {
min = proj;
}
else if(proj > max) {
max = proj;
}
}
var projection2 = [min, max];
if(projection1[1] > projection2[0] && projection1[0] < projection2[0]) {
}
else if(projection2[1] > projection1[0] && projection2[0] < projection1[0]) {
}
else {
return false; // return false if projections not overlapping on any one axis
}
}
return true; // return true if projections is overlapping on all the axes
};
:bulb: to format code use backticks! ``` more info
@marhyorh
function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
// Only change code above this line
return fahrenheit;
}
// Change the inputs below to test your code
convertToF(30);
// Only change code below this line
havoczz sends brownie points to @marhyorh :sparkles: :thumbsup: :sparkles:
:cookie: 709 | @marhyorh |http://www.freecodecamp.com/marhyorh
item
to the end of the array arr
. Start with that
item
item
you should returned the removed item
arr
and item
.
function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
// Only change code below this line
var x = Object.keys(source);
for(i=0;i<collection.length;i++){
for(j=0;j<x.length;j++){
if(collection[i].hasOwnProperty(x[j])&& collection[i][x[j]] === source[x[j]]){
arr.push(collection[i]);
}
}
}
// Only change code above this line
return arr;
}
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
this works only if source has a single key what I'm missing Please
FREE LOVE?
(by moving the character selection 13 places), my output is DREE >OVE?
which I don't get because the second if else tree works for the E's (R's in the input). Anyway, here's the code if anyone can give me a hint?function rot13(str) {
var rot13 = "";
for (var i = 0; i < str.length; i++){
if (90 >= str.charCodeAt(i) && str.charCodeAt(i) >= 65){
if (str.charCodeAt(i) < 78){
rot13 += String.fromCharCode(str.charCodeAt(i)+13);
} else {
var num = 90 - str.charCodeAt(i);
rot13 += String.fromCharCode(61+num);
}
} else {
rot13 += str[i];
}
}
return rot13;
}
// Change the inputs below to test
rot13("SERR YBIR?");
}else if(str.length<=3) {
newstr = str.slice(0,num+3);
newstr +=("...");
console.log(newstr,str.length,num);
return newstr;
}
return
keyword before the statement that uses .shift().
sohan2infosec sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2372 | @masd925 |http://www.freecodecamp.com/masd925
milos2709 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2373 | @masd925 |http://www.freecodecamp.com/masd925
return arr.shift();
mutates the array by removing the first element and the method returns it. Then return keyword returns that removed element from the function.
``` var newstr;
if(str.length>num){
newstr = str.slice(0,num-3);
newstr+=("...");
console.log(newstr,str.length);
return newstr;
}else if (num>=str.length){
return str;
}else if(str.length<=3) {
var num1= num;
newstr = str.slice(0,num1-3);
newstr +=("...");
console.log(num1,newstr,str.length);
return newstr;
} ```
Hi,I'm stuck on the Profile Lookup,as I don't understand the whats up with my if statement
function lookUpProfile(firstName, prop){
for (var i = 0;i < contacts.length;++i) {
if (contacts[i][firstName] == firstName && contacts[i][prop] == prop)
return contacts[i][prop];
}
}
I've already tried multiple tests but no matter what I can't seem to compare those two strings. I know that by using '===' both type and value have to be equal but with '==' this rule shouldn't apply
contacts[i][firstName]
<- quotes needed on firstName here
// Setup
var testString = "Ada Lovelace and Charles Babbage designed the first computer and the software that would have run on it.";
// Example
var expressionToGetSoftware = /software/gi;
var softwareCount = testString.match(expressionToGetSoftware).length;
// Only change code below this line.
var expression = /and./gi; // Change this Line
// Only change code above this line
// This code counts the matches of expression in testString
var andCount = testString.match(expression).length;
shxdow sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2374 | @masd925 |http://www.freecodecamp.com/masd925
FREE LOVE?
(by moving the character selection 13 places), my output is DxRExEx >xOVEx?
(the x's there to check which if/else chain it goes down - which I don't get because it works for the E's (R's in the input), but not the S
or the Y
. Anyway, here's the code if anyone can give me a hint?function rot13(str) {
var rot13 = "";
console.log('ABZ'.charCodeAt(2));
for (var i = 0; i < str.length; i++){
if (90 >= str.charCodeAt(i) && str.charCodeAt(i) >= 65){
if (str.charCodeAt(i) < 78){
rot13 += String.fromCharCode(str.charCodeAt(i)+13);
} else {
var num = 90 - str.charCodeAt(i);
rot13 += String.fromCharCode(61+num) + "x";
}
} else {
rot13 += str[i];
}
}
return rot13;
}
// Change the inputs below to test
rot13("SERR YBIR?");
prop
.
sohan2infosec sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: sohan2infosec already gave masd925 points
prop
. Simple .hasOwnProperty() test on the object is enough.
this is my code function palindrome(str) {
// Good luck!
var liman = str.replace(/[^A-Za-z0-9]/g, '');
if (liman === liman.split('').reverse().join('')) {
return true;
}
else return false;
}
palindrome("eye");
@shxdow contacts[i][firstName]
<- quotes needed on firstName here
for (var i = 0;i < contacts.length;++i) {
if (contacts[i].hasOwnProperty(firstName) && contacts[i].hasOwnProperty(prop)) {
if (contacts[i][firstName] == firstName && contacts[i][prop] == prop)
return contacts[i][prop];
}
}
"firstName"
. Nothing to do with the value of function parameterfirstName
that would be used on the code your posted there contacts[i][firstName]
contacts[i]["firstName"] === firstName
on the first and contacts[i].hasOwnProperty(prop)
on the second if.
function golfScore(par, strokes) {
// Only change code below this line
return "Change Me";
// Only change code above this line
}
// Change these values to test
golfScore(5, 4);
shxdow sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2375 | @masd925 |http://www.freecodecamp.com/masd925
meeeeeeeeeeeeeeeee
var myStr = 'FirstLine\n SecondLine\\ ThirdLine\r’
var myStr = 'FirstLine\n SecondLine\\ ThirdLine\r’
FirstLine
\SecondLine\
ThirdLine
var myStr = 'FirstLine\n \SecondLine\ \rThirdLine';
var myStr = 'FirstLine\n \\SecondLine\\ \rThirdLine’;
pinglinh sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2886 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
pinglinh sends brownie points to @alexanderkopke and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: pinglinh already gave sjames1958gm points
:cookie: 726 | @alexanderkopke |http://www.freecodecamp.com/alexanderkopke
Help me with Word Blanks pls
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("cat", "little", "hit", "slowly");
me with word blanks plsfunction wordblanksmynoun 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 functionwordblankscat little hit slowly
wordBlanks("dog", "big", "ran", "quickly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
wordBlanks("cat", "little", "hit", "slowly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
"catlittlehitslowly"
from the function is not a sensible sentence.
I tried with
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("cat,", " little,", " hit,", " slowly.");
but doesnt work
"A large "+myNoun+" ate my dinner."
In that fassion.
myNoun
etc. You use the parameters to make a big sentence (string).
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
result = "A "+myAdjective+" "+myNoun+" ate my dinner "+myAdverb+", and then I "+myVerb+"the table.";
// Your code above this line
return result;
}
// Change the words here to test your function
wordBlanks("cat", "little", "hit", "slowly");
'use strict';
at the start of function. It should be there on its own line.
// global stuff
function name(name) {
return name; // Stuff in the local scope to the function.
}
// More of that global stuff.
arguments
object.
danydin sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2887 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
format
var code = undefined;
mesmoiron sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2377 | @masd925 |http://www.freecodecamp.com/masd925
var myArray = Array.prototype.slice.call(arguments,1)
or var myArray = array.slice.call(arguments,1)
slice()
method which is a property of the Array prototype
[].slice()
is shorter to write than Array.prototype.slice()
. No difference otherwise.
function lookUpProfile(firstName, prop){
// Only change code below this line
for(i=0; i<contacts.length;i++){
for( var key in contacts[i]){
if (firstName == contacts[i].firstName && contacts[i].hasOwnProperty(prop)){
return contacts[i].firstName;
return contacts[i].prop;
}
}
}
// Only change code above this line
}
jamesmillerho sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2888 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
dbeczuk sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2378 | @masd925 |http://www.freecodecamp.com/masd925
<canvas id="one" height="200" width="200"></canvas>
this worked
jamesmillerho sends brownie points to @sjames1958gm and @bkinahan :sparkles: :thumbsup: :sparkles:
:warning: jamesmillerho already gave sjames1958gm points
:star2: 2316 | @bkinahan |http://www.freecodecamp.com/bkinahan
sjames1958gm sends brownie points to @jamesmillerho :sparkles: :thumbsup: :sparkles:
:cookie: 402 | @jamesmillerho |http://www.freecodecamp.com/jamesmillerho
if () { return; } else { return; }
)
privateroom5 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2889 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
function updateRecords(id, prop, value) {
if (prop === "tracks" && value !==""){
if (collection[id][prop]){
(collection[id][prop].push(value));
} else{
collection[id][prop] = [value];
} else if (value !==""){
collection[id][prop] = [value];
}else{
delete collection[id][prop];
}
}
return collection;
}
sup lads. can someone heck what's wrong with this?
[value];
value !== ''
within one if
block:if ( value !== '' ) {
// do the things here if the value is not blank
} else {
// do the things here if the value is blank
}
Dear all,
I am working at Profile Lookup task
my code as below,it's dosen't work,any can help me?
function lookUpProfile(firstName, prop){
// Only change code below this line
var _type;
for(var i=0;i<contacts.length;i++){
if(contacts[i].firstName!=firstName)
{_type="No such contact";}
else{
switch(prop){
case "lastName":_type=contacts[i].lastName;
break;
case "number":_type=contacts[i].number;
break;
case "likes":_type=contacts[i].likes;
break;
default: _type="No such property";
}
}
}
return _type;
function lookUpProfile(firstName, prop){
// Only change code below this line
var _type;
for(var i=0;i<contacts.length;i++){
if(contacts[i].firstName!=firstName)
{_type="No such contact";}
else{
switch(prop){
case "lastName":_type=contacts[i].lastName;
break;
case "number":_type=contacts[i].number;
break;
case "likes":_type=contacts[i].likes;
break;
default: _type="No such property";
}
}
}
return _type;
// Only change code above this line
}
// Example
var firstName = "Tyler";
var lastName = "Langan";
// Only change code below this line
tylerl-uxai sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 2017 | @moigithub |http://www.freecodecamp.com/moigithub
tylerl-uxai sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:warning: tylerl-uxai already gave moigithub points
:star2: 1911 | @ndburrus |http://www.freecodecamp.com/ndburrus
ashish1729 sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
hello everyone. i have a question for record collection challenge. can anyone tell me why doesn't this code work? 'function updateRecords(id, prop, value) {
if(prop !== "tracks" && value !== ""){
collection[id][prop] = value;
}
else if(prop === "tracks"){
if(!collection[id].hasOwnProperty(prop)){
collection[id].tracks = [];
}
collection[id].tracks.push(value);
}
else if(prop === "tracks" && value !== ""){
if(collection[id].hasOwnProperty(prop)){
collection[id].tracks.push(value);
}
}
else if(value === ""){
delete collection [id][prop];
}
return collection;
}
'
function lookUpProfile(firstName, prop){
// Only change code below this line
for(i=0; i<contacts.length;i++){
if (firstName == contacts[i].firstName && contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
}
}
for(i=0; i<contacts.length;i++){
if(firstName !== contacts[i].firstName){
return "No such contact";
}
}
for(i=0;i<contacts.length;i++){
if(contacts[i].hasOwnProperty(prop) === false){
return "No such property";
}
}
// Only change code above this line
}
function largestOfFour(arr) {
// You can do this!
var result = new Array();
var current = new Array();
for(var i = 0; i < arr.length; i++) {
for(var j = 0; j < arr[i].length; j++){
current[i] = sort(arr[i][j]);
}
result[i][j] = current[i];
}
return result;
}
function sort(arr) {
for(var i = 0; i < arr.length; i++) {
for(var j = 0; j < i; j++) {
if(arr[i] > arr[j]) {
var temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
return arr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
natto278 sends brownie points to @sjames1958gm and @masd925 and @athaman and @wearenotgroot and @jupiterpenny :sparkles: :thumbsup: :sparkles:
:star2: 2890 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:cookie: 333 | @jupiterpenny |http://www.freecodecamp.com/jupiterpenny
:star2: 2379 | @masd925 |http://www.freecodecamp.com/masd925
:cookie: 622 | @athaman |http://www.freecodecamp.com/athaman
:star2: 1474 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
firstName
in order to properly return the "No such property" status - your code does not properly do that check. In fact, you can eliminate the multiple for
loops and put all of the testing and checking into the body of one for
loop. (Keeping in mind that you have to be careful about the "No such contact" return...)
{ Error: ENOENT: no such file or directory, open '.env'
2016-08-27T14:55:25.237516+00:00 app[web.1]: at Error (native)
2016-08-27T14:55:25.237517+00:00 app[web.1]: at Object.fs.openSync (fs.js:634:18)
2016-08-27T14:55:25.237517+00:00 app[web.1]: at Object.fs.readFileSync (fs.js:502:33)
2016-08-27T14:55:25.237518+00:00 app[web.1]: at Object.module.exports.config (/app/node_modules/dotenv/lib/main.js:30:37)
2016-08-27T14:55:25.237519+00: