get help in general - we have more specialized help rooms here: https://gitter.im/FreeCodeCamp/home
hello people! wanted to know if I could get a little help on on challenge: Waypoint: Change the Font Size of an Element.<style>
.red-text {
color: red;
}
</style>
<h2 class='red-text'>CatPhotoApp</h2>
{ font-size: 16px; }
<p class='red-text'>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
function inventory(arr1, arr2) {
// All inventory must be accounted for or you're fired!
return arr2.reduce(function(stockArr,stockItem){
var updated = false;
stockArr.forEach(function(item){
if(item[1] == stockItem[1]){
item[0] = stockItem[0] + item[0];
updated = true;
}
});
if (updated === false){
stockArr.push(stockItem);
}
return stockArr;
},arr1).sort(function(a,b){
return (a[1].toUpperCase() > b[1].toUpperCase());
});
}
Sorry, can't find a bonfire called euclid. [ Check the map? ]
Sorry, can't find a bonfire called loop. [ Check the map? ]
type bonfire name
to get some info on that bonfire. And check HelpBonfires chatroom
function add() {
return false;
}
add(2,3);
Create a function that sums two arguments together. If only one argument is provided, return a function that expects one additional argument and will return the sum.
For example, add(2, 3) should return 5, and add(2) should return a function that is waiting for an argument so that <code>var sum2And = add(2); return sum2And(3); // 5</code>
If either argument isn't a valid number, return undefined.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.
type:
bf details
bf links
bf spoiler
return (b[1].toUpperCase() > a[1].toUpperCase()) ? 1 : (b[1].toUpperCase() < a[1].toUpperCase()) ? -1 : 0;
" above and "
" below
thescuba sends brownie points to @gazzer82 :sparkles: :thumbsup: :sparkles:
'''<link rel='stylesheet' href='//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css'/>
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, Monospace;
}
p {
font-size: 16px;
font-family: Monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 50%;
}
.smaller-image {
width: 100px;
}
</style>
<h2 class='red-text'>CatPhotoApp</h2>
<p>Click here for <a href='#'>cat photos</a>.</p>
<a href='#'><img class='smaller-image thick-green-border img-responsive' src='http://bit.ly/fcc-kittens'/></a>
<a href='#'><img class='smaller-image thick-green-border img-responsive' src='http://bit.ly/fcc-kittens2'/></a>
'''
<link rel='stylesheet' href='//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css'/>
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, Monospace;
}
p {
font-size: 16px;
font-family: Monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 50%;
}
.smaller-image {
width: 100px;
}
</style>
<h2 class='red-text'>CatPhotoApp</h2>
<p>Click here for <a href='#'>cat photos</a>.</p>
<a href='#'><img class='smaller-image thick-green-border img-responsive' src='http://bit.ly/fcc-kittens'/></a>
<a href='#'><img class='smaller-image thick-green-border img-responsive' src='http://bit.ly/fcc-kittens2'/></a>
thescuba sends brownie points to @oneate7 :sparkles: :thumbsup: :sparkles:
:star: 2 | @oneate7 | http://www.freecodecamp.com/oneate7
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, Monospace;
}
p {
font-size: 16px;
font-family: Monospace;
}
.thick-green-border {
border-color: green;
border-width: 10px;
border-style: solid;
border-radius: 50%;
}
.smaller-image {
width: 100px;
}
</style>
<h2 class='red-text'>CatPhotoApp</h2>
<p>Click here for <a href='#'>cat photos</a>.</p>
<a href='#'><img class='smaller-image thick-green-border' src='https://bit.ly/fcc-kittens'/></a>
<a href='#'><img class='smaller-image thick-green-border img-responsive' src='http://bit.ly/fcc-kittens2'/></a>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagna</li>
</ul>
<p>Top 3 things cats hate:</p>
<ol>
<li>flea treatment</li>
<li>thunder</li>
<li>other cats</li>
</ol>
<form action="/submit-cat-photo">
<label><input type='radio' name='indoor-outdoor'> Indoor</label>
<label><input type='radio' name='indoor-outdoor'> Outdoor</label>
<br>
<label><input type='checkbox' name='personality'> Loving</label>
<label><input type='checkbox' name='personality'> Lazy</label>
<label><input type='checkbox' name='personality'> Crazy</label>
<br>
<input type='text' placeholder='cat photo URL' required>
<button type='submit'>Submit</button>
</form>
function mutation(arr) {
var i = 0;
// split strings into arrays of lower case letters
var first = arr[0].toLowerCase().split("");
var second = arr[1].toLowerCase().split("");
//offset
var len = second.length;
// while each item of second array
while (i < len ) {
// if first array has element of the second array
if (first.indexOf(second[i])) {
// keep looping
i++;
// else, it is false
} else {
return false;
}
}
// if loop didn't stop earlier with false, return true
return true;
}
mutation(['hello', 'hey']);
function mutation(arr) {
return arr;
}
mutation(['hello', 'hey']);
Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.
For example, ['hello', 'Hello'], should return true because all of the letters in the second string are present in the first, ignoring case.
The arguments ['hello', 'hey'] should return false because the string 'hello' does not contain a 'y'.
Lastly, ['Alien', 'line'], should return true because all of the letters in 'line' are present in 'Alien'.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.
type:
bf details
bf links
bf spoiler
indexOf
first.indexOf(second[i]) >= 0
pwdd sends brownie points to @gazzer82 :sparkles: :thumbsup: :sparkles:
function convert(num) {
var result = "";
var ones = ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"];
var tens = ["X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"];
var huns = ["C", "CC", "CCC", "CD", "D", "MD", "MDD", "MDDD", "CM"];
if(num > 100 && num < 10000) {
result += huns[Math.floor(num / 100) - 1];
num = num % 100;
}
if(num > 10) {
result += tens[Math.floor(num / 10) - 1];
num = num % 10;
}
if(num > 0) {
result += ones[num - 1];
}
return result;
}
convert(36);
......
return answer.join('');
}
convert(29);
FCC console displays "XXIX" (correct) but server says :gazzer82 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
function convert(numArg) {
function Numerals(numAr,mag){
var scaLe = [];
scaLe[1]= [1,"I",'IV','V','IX'];
scaLe[10]= [10,"X",'XL','L','XC'];
scaLe[100]= [100,"C",'CD','D','CM'];
scaLe[1000]= [1000,"M","MMMM","MMMMM","MMMMMMMMM"];
var fNum = '';
var check = numAr / scaLe[mag][0];
switch (true) {
case ((numAr >= 1*scaLe[mag][0]) && (numAr < 4*scaLe[mag][0])):
fNum = scaLe[mag][1].repeat(check);
break;
case (numAr == 4*scaLe[mag][0]):
fNum = scaLe[mag][2];
break;
case (numAr == 9*scaLe[mag][0]):
fNum = scaLe[mag][4];
break;
case (numAr >= 5*scaLe[mag][0] && numAr < 10*scaLe[mag][0]):
fNum = scaLe[mag][3];
fNum = fNum.concat(scaLe[mag][1].repeat(check - 5));
break;
case (numAr == 10*scaLe[mag][0]):
fNum = scaLe[mag*10][1];
break;
default: console.log("error0"); } return fNum;}
var answer =[];
while (numArg > 0){
switch(true){
case (numArg >=1000):
answer.push(Numerals(numArg, 1000));
numArg = numArg % 1000;
break;
case ((numArg >=100) && (numArg < 999)):
answer.push(Numerals(numArg, 100));
numArg = numArg % 100;
break;
case ((numArg >=10) && (numArg < 99)):
answer.push(Numerals(numArg, 10));
numArg = numArg % 10;
break;
case ((numArg >= 1) && (numArg < 11)):
answer.push(Numerals(numArg,1));numArg = -1;
break;
default: numArg = -1; console.log(numArg + " error2");
}
}
return answer.join('');
}
convert(29);
var i = str.search(/[A-Z]/);
how do I resume search from the returned index?
This an inline `<paste code here>
` code formatting with a single backtick(`) at start and end around the code
.
``` ⇦ Type 3 backticks, then press [shift + enter ⏎]
<paste your code here>,
then press [shift + enter ⏎]
``` ⇦ Type 3 backticks, then press [enter ⏎]
See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics
spinal
update
to reload it here
Sorry, can't find a bonfire called spinalcase. [ Check the map? ]
function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
return str;
}
spinalCase('This Is Spinal Tap');
Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.
type:
bf details
bf links
bf spoiler
function convert(str) {
var newStr = str.replace(/\&/g, "&");
newStr = newStr.replace(/</g, "<");
newStr = newStr.replace(/\>/g, ">");
newStr = newStr.replace(/\"/g, """);
newStr = newStr.replace(/\'/g, "&apos");
return newStr;
}
convert('Dolce & Gabbana');
"&"
should be "&"
.
Here's what I got for the roman numeral bonfire:
function convert(num) {
var roman = [//0 1 2 3 4 5 6 7 8 9
["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"], // Units
["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"], // Tens
["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"], // Hundreds
["", "M"] // Thousands
];
var romanized = [];
num.toString().split('').reverse().forEach(function(digit, index) {
romanized.unshift(roman[index][digit]);
});
return romanized.join('');
}
convert(36);
I really tried to avoid declaring an empty variable but I just couldn't find a reverse iterative method in the array prototype :S
type bonfire name
to get some info on that bonfire. And check HelpBonfires chatroom
var t = [2, 3, 4, 1, 5];
t.forEach( function(n){
document.createElement('div').innerHTML(n)
document.createTextNode('click me')
})
t.forEach(function(n){
x = document.createElement('div');
x.innerHTML = '<span></span>';
y = document.createTextNode(n);
x.appendChild(y);
document.body.appendChild(x);
});
var languages = {
english: "Hello!",
french: "Bonjour!",
notALanguage: 4,
spanish: "Hola!"
};
// print hello in the 3 different languages
for (var prop in languages) {
if (languages[prop].typeof === 'string') {
console.log(languages[prop]);
}
}
Does anyone remember this one? It keeps erroring saying I did not print out the strings for Hello
if (typeof languages[prop] === 'string') {
if (typeof(languages[prop]) === 'string')
parseInt(booleanString, 2)
@SaintPeter
var t = [3,4,5,36]
t.forEach(function(n){
x = document.createElement('h4');
//x.innerHTML = '<span></span>';
y = document.createTextNode(n);
x.appendChild(y);
document.body.appendChild(x);
});
so i have to create the node element, then create the text node, then attach the text node to the node element, then attach the node element to the document body? what a fkkkk madness
This an inline `<paste code here>
` code formatting with a single backtick(`) at start and end around the code
.
``` ⇦ Type 3 backticks, then press [shift + enter ⏎]
<paste your code here>,
then press [shift + enter ⏎]
``` ⇦ Type 3 backticks, then press [enter ⏎]
See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics
$(document).ready(function() {
$('div').hover(function() {
$('div').addclass('red');
});
});
majeye sends brownie points to @biancamihai and @flota113 :sparkles: :thumbsup: :sparkles:
:star: 6 | @flota113 | http://www.freecodecamp.com/flota113
but even for a code such as the below
```
function findLongestWord(str) {
return str.length;
}
findLongestWord('The quick brown fox jumped over the lazy dog');
Question about palindrome Bonfire
It doesn't like this regular expression: [^a-zA-Z0-9]
It says that the ^ is an unexpected token. Does anyone know why?
^
with a back slash \^
Ok, this seems to have solved the problem partially:
/[^a-zA-Z0-9]/g
/[a-zA-Z0-9]/g
?
^
?
/^[a-zA-Z0-9]/g
outside bracket
I'm trying to remove the commas, spaces and periods from:
A man, a plan, a canal. Panama
.replace()
to make regex remove things
/[a-zA-Z0-9]/g
then do the reverse of this is doing ^^
I'm confused about why:
str = str.replace(/[^a-zA-Z0-9]/g,"");
Doesn't work.
"HELLO WORLD".replace( /[L]/g, '')
=> "HEO WORD"
If you're having troll problems notify admins here
type bonfire name
to get some info on that bonfire. And check HelpBonfires chatroom
function where(collection, source) {
var arr = [];
// What's in a name?
return arr;
}
where([{ first: 'Romeo', last: 'Montague' }, { first: 'Mercutio', last: null }, { first: 'Tybalt', last: 'Capulet' }], { last: 'Capulet' });
Make a function that looks through a list (first argument) and returns an array of all objects that have equivalent property values (second argument).
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.
type:
bf details
bf links
bf spoiler
I got
function pairwise(arr, arg) {
var filtered = function(value) {
return arr.indexOf(value) !== i;
};
var pairwisers = [];
console.log("arr = " + arr);
console.log("Begin i loop");
for(i = 0; i < arr.length; i++) {
var arrNew = arr.filter(filtered);
console.log("arr[i] = " + arr[i]);
console.log("arrNew = " + arrNew);
for(j = 0; j < arrNew.length; j++) {
if(arr[i] + arrNew[j] === arg) {
console.log("pairwisers before = " + pairwisers);
console.log("Pairwisers when arrNew[j] " + arrNew[j] + " & arr[i] = " + arr[i]);
if(pairwisers.indexOf(arrNew[j]) === -1) {
pairwisers.push(arrNew[j]);
}
if(pairwisers.indexOf(arr[i]) === -1) {
pairwisers.push(arr[i]);
}
console.log("pairwisers after = " + pairwisers);
}
}
}
var sum = 0;
for(k = 0; k < pairwisers.length; k++) {
sum += arr.indexOf(pairwisers[k]);
if(arr.indexOf(pairwisers[k]) === 0 && arr.indexOf(pairwisers[k], 1) !== -1) { // cba making a for loop to find the index to start wtih lol
sum += arr.indexOf(pairwisers[k], 1);
}
}
return sum;
}
but it's pretty bad
function drawer(price, cash, cid) {
var string_to_number = {
"PENNY": 0.01,
"NICKEL": 0.05,
"DIME": 0.1,
"QUARTER": 0.25,
"ONE": 1,
"FIVE": 5,
"TEN": 10,
"TWENTY": 20,
"ONE HUNDRED": 100,
};
var change_arr = [];
var change_due = cash - price;
var total_drawer = cid.reduce(function(prev, curr, index) {
return prev + curr[1];
}, 0);
console.log(total_drawer);
if(total_drawer < change_due) {
return "Insufficient Funds";
} else if( total_drawer === change_due) {
return "Closed";
} else {
cid.reverse();
cid = cid.map(function(unit) {
var initial_amount = unit[1];
if(change_due / string_to_number[unit[0]] >= 1) {
var count = 0;
while(change_due / string_to_number[unit[0]] >= 1) {
change_due -= string_to_number[unit[0]];
initial_amount -= string_to_number[unit[0]];
count++;
}
change_arr.push([unit[0], (string_to_number[unit[0]]*count)]);
return [unit[0], initial_amount];
} else {
return [unit[0], unit[1]];
}
});
}
return change_arr;
}
// Example cash-in-drawer array:
// [['PENNY', 1.01],
// ['NICKEL', 2.05],
// ['DIME', 3.10],
// ['QUARTER', 4.25],
// ['ONE', 90.00],
// ['FIVE', 55.00],
// ['TEN', 20.00],
// ['TWENTY', 60.00],
// ['ONE HUNDRED', 100.00]]
drawer(19.50, 20.00, [['PENNY', 1.01], ['NICKEL', 2.05], ['DIME', 3.10], ['QUARTER', 4.25], ['ONE', 90.00], ['FIVE', 55.00], ['TEN', 20.00], ['TWENTY', 60.00], ['ONE HUNDRED', 100.00]]);
royshouvik sends brownie points to @oab00 :sparkles: :thumbsup: :sparkles:
:star: 181 | @oab00 | http://www.freecodecamp.com/oab00
@natac13
for the test:
drawer(3.26, 100.00, [['PENNY', 1.01], ['NICKEL', 2.05], ['DIME', 3.10], ['QUARTER', 4.25], ['ONE', 90.00], ['FIVE', 55.00], ['TEN', 20.00], ['TWENTY', 60.00], ['ONE HUNDRED', 100.00]])
this is what it's expecting in the return:
[ ['TWENTY', 60.00], ['TEN', 20.00], ['FIVE', 15], ['ONE', 1], ['QUARTER', 0.50], ['DIME', 0.20], ['PENNY', 0.04] ]
this is what your function returns:
[ ["TWENTY", 80], ["TEN", 10], ["FIVE", 5], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.03] ]
60
of twenty bills but your function gives out 80
of twenty billsfunction drawer(price, cash, cid) {
var string_to_number = {
"PENNY": 0.01,
"NICKEL": 0.05,
"DIME": 0.1,
"QUARTER": 0.25,
"ONE": 1,
"FIVE": 5,
"TEN": 10,
"TWENTY": 20,
"ONE HUNDRED": 100,
};
var change_arr = [];
var change_due = cash - price;
var total_drawer = cid.reduce(function(prev, curr, index) {
return prev + curr[1];
}, 0);
console.log(total_drawer);
if(total_drawer < change_due) {
return "Insufficient Funds";
} else if( total_drawer === change_due) {
return "Closed";
} else {
cid.reverse();
cid = cid.map(function(unit) {
var initial_amount = unit[1];
if(change_due / string_to_number[unit[0]] >= 1) {
var count = 0;
while(change_due / string_to_number[unit[0]] >= 1 && initial_amount > 0) {
change_due -= string_to_number[unit[0]];
initial_amount -= string_to_number[unit[0]];
count++;
}
change_arr.push([unit[0], (string_to_number[unit[0]]*count)]);
return [unit[0], initial_amount];
} else {
return [unit[0], unit[1]];
}
});
}
return change_arr;
}
drawer(3.26, 100.00, [['PENNY', 1.01], ['NICKEL', 2.05], ['DIME', 3.10], ['QUARTER', 4.25], ['ONE', 90.00], ['FIVE', 55.00], ['TEN', 20.00], ['TWENTY', 60.00], ['ONE HUNDRED', 100.00]]);
$(document).ready(function() {
var coords =getWeather();
});
function getWeather(){
var arr=[];
$.getJSON("https://freegeoip.net/json/?callback=?",function(json){
var city = json.city;
$('#city').text(city);
weatherInfo(city);
});
}
function weatherInfo(city){
var url="http://api.openweathermap.org/data/2.5/weather?q="+city+"&APPID=cee148fb0779f2a22dca2f1c4fdb911c";
$.getJSON(url,function(weather){
console.log(city);
var general=weather.weather[0].main;
var description = weather.weather[0].description;
var kTemp= weather.main.temp;
var cTemp= Math.round((kTemp-273.15)*100)/100;
var fTemp = cTemp*1.8+32;
$('#temp').text(cTemp+" C");
$('#desc').text(description.slice(0,1).toUpperCase()+description.slice(1));
});
}
How do I make the cTemp and fTemp in my weatherInfo() function available to the global scope?
var cTemp;
function(){
//use cTemp
cTemp = 5;
console.log(cTemp);
}
var cTemp;
$(document).ready(function() {
var coords =getWeather();
console.log(cTemp);
});
function getWeather(){
var arr=[];
$.getJSON("https://freegeoip.net/json/?callback=?",function(json){
var city = json.city;
$('#city').text(city);
weatherInfo(city);
});
}
function weatherInfo(city){
var url="http://api.openweathermap.org/data/2.5/weather?q="+city+"&APPID=cee148fb0779f2a22dca2f1c4fdb911c";
$.getJSON(url,function(weather){
console.log(city);
var general=weather.weather[0].main;
var description = weather.weather[0].description;
var kTemp= weather.main.temp;
cTemp= Math.round((kTemp-273.15)*100)/100;
fTemp = cTemp*1.8+32;
$('#temp').text(cTemp+" C");
$('#desc').text(description.slice(0,1).toUpperCase()+description.slice(1));
$('#optionsRadios2').click(function(){
$('#temp').text(fTemp+ " F");
});
$('#optionsRadios1').click(function(){
$('#temp').text(cTemp+ " C");
});
});
}
$.getJSON("https://freegeoip.net/json/?callback=?",function(json){
var city = json.city;
$('#city').text(city);
weatherInfo(city);
//here call function or just do whatever You need with data
});
var temp;
function gotData() {
console.log(temp);
}
$.getJSON('url', function(data) {
temp = data.temperature;
gotData();
});
.class {
font: Monospace !important;
}
hey, any reason this wouldn't work?
<div ng-show="story.description.length > 0" class="description">
{{story.description.length}}
</div>
it doesn't matter what evaluation I make, it still shows the div with 0 in it. (i made it write the length of itself to debug)
It's on line 17
http://codepen.io/Miauwi/pen/WvmpQd
function add() {
return false;
}
add(2,3);
Create a function that sums two arguments together. If only one argument is provided, return a function that expects one additional argument and will return the sum.
For example, add(2, 3) should return 5, and add(2) should return a function that is waiting for an argument so that <code>var sum2And = add(2); return sum2And(3); // 5</code>
If either argument isn't a valid number, return undefined.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.
type:
bf details
bf links
bf spoiler
andreiamlm sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
‘’'
function binaryAgent(str) {
// Check if string matches 1s & 0s & repeats 8 times
if(str.match(/[10]{8}/g))
{
// Match regex -> map string to function
var wordsFromBin = str.match(/([10]{8}|\s+)/g).map(function(fromBinary)
{
// parseInt fromBinary on the base of 2
/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
/
return String.fromCharCode(parseInt(fromBinary, 2) );
}).join('');
//console.log(wordsFromBin);
return wordsFromBin;
}
}
binaryAgent('01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111');
‘''
match
update
to reload it here
andreiamlm sends brownie points to @miauwi :sparkles: :thumbsup: :sparkles:
i'm on bonfire 20. i can't pass the last test. here is the error message :
assert.deepEqual(diff([], ['snuffleupagus', 'cookie monster', 'elmo']), ['snuffleupagus', 'cookie monster', 'elmo'], 'empty array');
empty array: expected [ Array(3) ] to deeply equal [ Array(3) ]
what does that mean ?
['snuffleupagus', 'cookie monster', 'elmo’]
doen’t equal the array returned by your function
Hi all, I'm working on the 8th bonfire and am a bit stuck. So far, I'm able to sort and return the first three of the four nested arrays. For some reason though, the fourth nested array won't sort! The only methods the problem description mention are the comparison operators. Should I attempt to solve the problem with comparison operators or can it be done with a for loop/calling the sort function like i'm doing? Here's my code:
```largestOfFour = [[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]];
for(i = 0; i <= 3; i++) {
sortedArr = largestOfFour[i].sort();
newArr = [[],[],[],[]];
newArr.push(largestOfFour[i].pop());
console.log(newArr);
}
```
largestOfFour = [[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]];
for(i = 0; i <= 3; i++) {
sortedArr = largestOfFour[i].sort();
newArr = [[],[],[],[]];
newArr.push(largestOfFour[i].pop());
console.log(newArr);
}
//Title Case a Sentence
function titleCase(str) {
str.split(" ");
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
}
titleCase("I'm a little tea pot");
largestOfFour = [[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]];
for(i = 0; i <= 3; i++) {
sortedArr = largestOfFour[i].sort(function(a,b){
return a - b;
});
newArr = [[],[],[],[]];
newArr.push(largestOfFour[i].pop());
console.log(newArr);
}
newArr = [[],[],[],[]];
in middle of ur for/loop.. everytime it "loops" will delete previous value, and reasign `newArr = [[],[],[],[]];' so ur push only will have newArr = [[],[],[],[]]; + last value pushed
`function palindrome(str) {
var newString =str.replace(/[^\w\s{}]|_/g,"").replace(/\s{1,}/g,"").toLowerCase();
var newStringWoSpace = newString.split('').reverse().join('');
if(newString === newStringWoSpace){
return true;
}
// Good luck!
else {
return false;
}
}
palindrome("A man, a plan, a canal. Panama");
`
```function <--- not on same line
should be
```
function
Holy cow... that's not how I have it at all. Maybe I need to redo the whole thing...
function palindrome(str) {
str = str.replace(/\s/, '');
str = str.replace(/\W/, '');
var reverseStr = str.split([[]]);
reverseStr = reverseStr.reverse([[]]);
reverseStr = reverseStr.join([[]]);
if (str === reverseStr) {
return true;
}
else {
return false;
}
return str.toLowerCase;
}
palindrome("eye");
function where(collection, source) {
var arr = [];
// get array of keys from source
var sourceKeys = Object.keys(source);
// loop through collection
for (i = 0; i < collection.length; i++) {
// loop through sourceKeys
for (x = 0; x < sourceKeys.length; x++) {
// if key is in collection
if (collection[i].hasOwnProperty(sourceKeys[x])) {
// if found key has same value in collection obj and source obj
// HERE IS THE ERROR. IF I DO THIS USING VALUES, LIKE
// COLLECTION[2].LAST == SOURCE[0].LAST
// I GET TRUE
// HOWEVER, IF I USE THE BELOW CODE, IT GET
// COLLECTION[I].SOURCEKEYS IS UNDEFINED
if (collection[i].sourceKeys[x] === source.sourceKeys[x]) {
// add obj to new array
arr.push(collection[1]);
}
}
}
}
return arr;
}
where([{ first: 'Romeo', last: 'Montague' }, { first: 'Mercutio', last: null }, { first: 'Tybalt', last: 'Capulet' }], { last: 'Capulet' });
arr.push(collection[1]
) was fixed to arr.push(collection[i]
var obj = {keyOne: "valueOne", keyTwo: "valueTwo"}
Object.keys(obj)
[keyOne, keyTwo]
function where(collection, source) {
function where(collection, source) {
function add() {
var singleNum = arguments[0];
function addOneMore () {
return singleNum + arguments[0];
}
if (typeof arguments[0] !== 'number' || typeof arguments[1] !== 'number') {
return undefined;
} else if (arguments.length === 2) {
return arguments[0] + arguments[1];
} else if (arguments.length === 1) {
return addOneMore;
}
}
add(2)(3);
this is giving me the error --> add(...) is not a functionfunction add(n) {
if (typeof arguments[0] !== 'number' || typeof arguments[1] !== 'number')
return addOneMore(); <-- parentesis
function add() {
var singleNum = arguments[0];
function addOneMore (n) {
return singleNum + n;
}
if (typeof arguments[0] !== 'number' || typeof arguments[1] !== 'number') {
return undefined;
} else if (arguments.length === 2) {
return arguments[0] + arguments[1];
} else if (arguments.length === 1) {
return addOneMore();
}
}
add(2, 3);
function end(str, target) {
strLength = str.length;
lastLet = str.substr(strLength - 1, strLength)
if (lastLet === target) {
return true;
}
else {
return false;
}
}
console.log(end('Bastian', 'n'));
japfohl sends brownie points to @mistereo :sparkles: :thumbsup: :sparkles:
var square = new Object();
square.sideLength = 6;
square.calcPerimeter = function() {
return this.sideLength * 4;
};
// help us define an area method here
var calcArea = function () {
return this.sideLength * this.sideLength;
};
var p = square.calcPerimeter();
var a = square.calcArea();
code
`function findLongestWord(str) {
str = str.split(" ");
str.sort(function(a,b){
return b.length - a.length;
});
return str[0].length;
}
findLongestWord('The quick brown fox jumped over the lazy dog');
`
//var strReverse = str.split('').reverse().join(''); // 'lkjhgfdsa'
function reverseString(str) {
var strReverse = str.split('');
strReverse.reverse();
strRevrse.join('');
return str;
//var strReverse = str.split('').reverse().join(''); // 'lkjhgfdsa'
}
reverseString('hello');
function findLongestWord(str) {
str = str.split(" ");
str.sort(function(a,b){
return b.length - a.length;
});
return str[0].length;
}
findLongestWord('The quick brown fox jumped over the lazy dog');
var str = "bcda";
str.split("").sort();
strRevrse.join('');
-- typo...
function findLongestWord(str) {
//str = str.split(" ");
str.split(" ").sort(function(a,b){
return b.length - a.length;
});
return str[0].length;
}
findLongestWord('The quick brown fox jumped over the lazy dog');
function reverseString(str) {
var strReverse = str.split('');
strReverse.reverse();
strReverse.join('');
return strReverse;
//var strReverse = str.split('').reverse().join(''); // 'lkjhgfdsa'
}
reverseString('hello');
Not sure why this isn’t working either, after fixing my mistakes
temp=strReverse.reverse();
@RoadToCode822 join didn't mutate the source array;
strReverse.join('');
return strReverse;
Should be:
return strReverse.join('');
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<style>
.red-text {
color: red;
h2 {
font-family: Lobster, Monospace;
}
!important: <style> .urgently-blue { color: blue !important; }
p {
font-size: 16px;
font-family: Monospace;
}
</style>
<h2 class='red-text'>CatPhotoApp</h2>
<p class='red-text'>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p class='red-text'>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
function findLongestWord(str) {
str = str.split(" ").sort(function(a,b){
return b.length - a.length;
});
return str[0].length;
}
findLongestWord('The quick brown fox jumped over the lazy dog');
function reverseString(str) {
var strReverse = str.split('');
var temp = strReverse.reverse();
return temp.join("");
}
reverseString('hello');
function reverseString(str) {
return strReverse = str.split('').reverse.join("");
}
var arr = ['a', 'b', 'c', 'd'];
arr.join('');
// arr is still ['a', 'b', 'c', 'd'] not "abcd";
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<style>
.red-text urgently-red {
color: red !important;
h2 {
font-family: Lobster, Monospace;
}
p {
font-size: 16px;
font-family: Monospace;
}
</style>
<h2 class='blue-text'.urgently-red> CatPhotoApp</h2>
<p class='red-text'>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p class='red-text'>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
This an inline `<paste code here>
` code formatting with a single backtick(`) at start and end around the code
.
``` ⇦ Type 3 backticks, then press [shift + enter ⏎]
<paste your code here>,
then press [shift + enter ⏎]
``` ⇦ Type 3 backticks, then press [enter ⏎]
See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics
function truncate(str, num) {
// Clear out that junk in your trunk
return str;
}
truncate('A-tisket a-tasket A green and yellow basket', 11);
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a '...' ending.
Note that the three dots at the end add to the string length.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.
type:
bf details
bf links
bf spoiler
<style>
.red-text {
color: red;
}
.urgently-red {
color: red !important
}
h2 {
font-family: Lobster, Monospace;
}
p {
font-size: 16px;
font-family: Monospace;
}
</style>
<h2 class='blue-text urgently-red'>CatPhotoApp</h2>
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<style>
.red-text {
color: red;
}
.urgently-red!important;
}
h2 {
font-family: Lobster, Monospace;
}
p {
font-size: 16px;
font-family: Monospace;
}
</style>
<h2 class='blue-text urgently-red'> CatPhotoApp</h2>
<p class='red-text'>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p class='red-text'>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor\
var regex = new RegExp(target + "$");
if(str.match(regex)){
str = true;
}else{
str = false;
}
return str;
}
end('Bastian', 'n');
/3\.5/
/3\.5/g
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<style>
.red-text {
color: red;
}
h2 {
font-family: Lobster, Monospace;
}
p {
font-size: 16px;
font-family: Monospace;
}
.smaller-image{
width: 100px;
}
</style>
<h2 class='red-text'>CatPhotoApp</h2>
<img class = "smaller-image" src='https://bit.ly/fcc-kittens'/>
<p class='red-text'>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p class='red-text'>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
function chunk(arr, size) {
// Break it up.
return arr;
}
chunk(['a', 'b', 'c', 'd'], 2);
Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a multidimensional array.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.
type:
bf details
bf links
bf spoiler
function titleCase(str) {
return str;
}
titleCase("I'm a little tea pot");
Return the provided string with the first letter of each word capitalized.
For the purpose of this exercise, you should also capitalize connecting words like 'the' and 'of'.
Remember to use RSAP if you get stuck. Try to pair program. Write your own code.
type:
bf details
bf links
bf spoiler
:construction: Spoilers are only in the Bonfire's Custom Room :point_right:
// This part is working, now I need to loop it
function titleCase(str) {
var words = str.replace(myRegExp, "").toLowerCase().split(" ");
var myRegExp = /[^a-zA-Z][\.,-\/#!$%\^&\*;:{}=\-_`~()]?/ig;
console.log (words + ' <= word list');
for (i = 0; i <= words.length; i++){
var current = words[i].slice(0,1).toUpperCase() + words[i].slice(1).toLowerCase();
console.log(current + ' <= current word');
var titled = [];
titled.push(current);
console.log(titled + ' <= titled word list');
}
return titled;
};
titleCase('help I need somebody');
titled
in every iteration
function smallestCommons(arr) {
var numMin = Math.min(arr[0], arr[1]);
var numMax = Math.max(arr[0], arr[1]);
var numMultiplier = 1;
var arrBool = [];
for (var i = numMin; i < numMax; i++) {
if ( (numMax * numMultiplier) % i === 0) {
arrBool.push(true);
} else {
arrBool.push(false);
}
console.log("min " + numMin + " " + "max " + numMax + " " + "i " + i + " " + "mult " + numMultiplier);
}
console.log(arrBool);
if (arrBool.indexOf(false) == -1) {
return numMax * numMultiplier;
}
}
smallestCommons([1,5]);
function mutation(arr) {
var baseStr = arr[0].toLowerCase();
var searchStr = arr[1].toLowerCase().split('');
for (i = 0; i < searchStr.length; i++) {
if (baseStr.indexOf(searchStr[i]) < 0) {
return false;
}
else {
return true;
}
}
}
mutation(['hello', 'hey']);
i <= words.length
return
statement will break the entire for loop at first iteration
for
loop is short-circuiting with the return
statement
// This part is working, now I need to loop it
function titleCase(str) {
var words = str.replace(myRegExp, "").toLowerCase().split(" ");
var myRegExp = /[^a-zA-Z][\.,-\/#!$%\^&\*;:{}=\-_`~()]?/ig;
//console.log (words);
var titled = [];
for (i = 0; i <= words.length; i++){
var current = words[i].slice(0,1).toUpperCase() + words[i].slice(1).toLowerCase();
// console.log(current + ' <= current word');
titled.push(current);
console.log(titled + ' <= titled word list');
}
return titled;
}
titleCase('help I need somebody');
for
loop
i < words.length
function findLongestWord(str) {
var stringReplace = str.split(/\s/g);
console.log(stringReplace);
for (var i=0; i !== stringReplace.length; i++) {
console.log(stringReplace[i] + " has the length of " + stringReplace[i].length + " characters");
// var longest = "";
// if(stringReplace[i].length > longest.length ){
// longest.length += stringReplace[i].length ;
// console.log("This is the longest word: " + longest);
// }
}
}
findLongestWord('The quick brown fox jumped over the lazy dog');