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.
Can anyone help me shorten this code, or point me in the right direction. The answer was easy to get but it feels a little hacky the way I did it.
```
function findLongestWord(str) {
var words = str.split(" ");
var longestWord = 0;
for (var i=0; i<words.length; i++){
if (words[i].length > longestWord){
longestWord = words[i].length;
}
}
return longestWord;
}
findLongestWord("The quick brown fox jumped over the lazy dog");
reduce
willcoxdev sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 91 | @eyesore- |http://www.freecodecamp.com/eyesore-
function findLongestWord(str) {
return str
.split(' ')
.reduce( (result, word) => {
if(word.length > result.length) result = word
return result
})
}
:bulb: to format code use backticks! ``` more info
function factorialize(num) {
let solde = 1;
while(num > 1){
solde = solde * num;
num = num - 1;
}
return solde;
}
loopProtect is not defined
hey i dont understand what im doing wrong with this challenge
<body>
<script>
const dataset = [
[ 34, 78 ],
[ 109, 280 ],
[ 310, 120 ],
[ 79, 411 ],
[ 420, 220 ],
[ 233, 145 ],
[ 333, 96 ],
[ 222, 333 ],
[ 78, 320 ],
[ 21, 123 ]
];
const w = 500;
const h = 500;
const svg = d3.select("body")
.append("svg")
.attr("width", w)
.attr("height", h);
svg.selectAll("circle")
.data(dataset)
.enter()
.append("circle")
.attr("cx", (d, i) => d[0])
.attr("cy", (d, i) => h - d[1])
.attr("r", 5);
svg.selectAll("text")
.data(dataset)
.enter()
.append("text")
// Add your code below this line
.text((d) => d)
.attr("x",(d,i)=> d[0]+5)
.attr("y", (d,i)=> h-d[1]);
// Add your code above this line
</script>
</body>
please help
function factorialize(num) {
let solde = 1;
let vaa = num;
for (let i = 0; i < vaa.length; i++){
solde *= vaa;
vaa -= 1;
}
return solde;
}
@willcoxDev
except for one that looks like [1000, 1001, 857, 1]
its sorts it to 1 1000 1001 857
Yes. I understood mostly all the challenges prior to this.
Sometimes I needed a hint or help from the people here.
Sometimes I’d struggle, but eventually get it after asking or reading or watch.
But there were also some where my brain would just go blank @longnt80
davidmillerfl sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 291 | @longnt80 |http://www.freecodecamp.com/longnt80
`function truncateString(str, num) {
if (str.length > num) {
return str.slice(0, num);
}
}
truncateString("A", 1);`
@dbib This code:
function factorialize(num) {
let solde = 1;
while(num > 1){
solde = solde * num;
num = num - 1;
}
return solde;
}
Works for me as well.
davidmillerfl sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 92 | @eyesore- |http://www.freecodecamp.com/eyesore-
dbib sends brownie points to @revisualize and @eyesore :sparkles: :thumbsup: :sparkles:
:warning: @eyesore's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
:star2: 3995 | @revisualize |http://www.freecodecamp.com/revisualize
in Iterate Through an Array with a For Loop iam using this code should equal 20 but outputs 5
// Setup
var myArr = [ 2, 3, 4, 5, 6];
// Only change code below this line
for (var i = 0; i < myArr.length; i++) {
total += myArr[i];
}
var total = [i];
var total = [i];
indexOf
?
takenGrid.indexOf(pos === -1)
giveback007 sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 93 | @eyesore- |http://www.freecodecamp.com/eyesore-
multiArray[i].push(arr[j]);
function chunkArrayInGroups(arr, size) {
var multiArray = [];
for(var i=0;i<size;i++){
multiArray.push(i);
for(var j=0;j<arr.length;j++){
multiArray[i].push(arr[j]);
}
}
return arr;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
Array.filter()
. I'm fairly certain that I need to filter the array according to search criteria but the MDN is confusing.
push
methods
multiarray[i]
is not an array
tmag298 sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 94 | @eyesore- |http://www.freecodecamp.com/eyesore-
// someVar equals 'Hat' in the global scope
var someVar = "Hat";
function myFun() {
// someVar equals 'Head' inside this function
var someVar = "Head";
return someVar;
}
console.log(myFun()) // = 'Head'
console.log(someVar) // = 'Hat'
myFun()
that is invoking. Creating a variable is declaring. I'm not trying to be a grammar cop here, but just for future reference.
var b = a;
under the last comment:
function repeatStringNumTimes(str, num) {
var holder = [];
var re = /\b/g;
if (num < 0) {
return holder.toString();
}
for (var i = 0; i < num; i++) {
holder.push(str);
}
var a = holder.join("");
var b = a.replace(re, '"');
return b;
}
repeatStringNumTimes("abc", 4);
'abcabcabcabc'
Function to add an element from function parameter into a Linked List
this.add = function(element){
// Only change code below this line
var node = new Node(element);
if(this.size() === 0) {
this.element=element;
head = element;
}
else {
var dummyNode=0;
while(this.next!==null) {
dummyNode = this.element;
}
dummyNode.next = element;
}
length++;
// Only change code above this line
};
Any help on where am I going wrong?
function abTest(a, b) {
// Only change code below this line
if (a || b < 0) {
return undefined;
}
// Only change code above this line
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}
// Change values below to test your code
abTest(2,2);
array
since you've got methods like push
pop
shift
etc...
We will now use our knowledge of strings to build a "Mad Libs" style word game we're calling "Word Blanks". You will create an (optionally humorous) "Fill in the Blanks" style sentence.
You will need to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb.
You will also need to use additional strings, which will not change, and must be in between all of the provided words. The output should be a complete sentence.
We have provided a framework for testing your results with different words. The tests will run your function with several different inputs to make sure all of the provided words appear in the output, as well as your extra strings.
'myNoun'
it will output 'myNoun'
and not 'dog'
wordBlanks("dog", "big", "ran", "quickly");
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb)
"dog", "big", "ran", "quickly"
will be values for the parameters (myNoun, myAdjective, myVerb, myAdverb) in the functionresult
I'll give you a hint with a short version @karthiksagr
result = "The " + myAdjective + " " + myNoun;
this would be something like "The little cat"
but you need to come up with one on your own
function mutation(arr) {
if (arr[0].toLowerCase().indexOf(arr[1].toLowerCase())){
return true;
}
return false;
}
mutation(["hello", "Hello"]);
mutation(['hello', 'hEllo'])
?
function mutation(arr) {
var m=arr[0].toLowerCase();
var n=arr[1].toLowerCase();
for(var i=0;i<n.length;i++)
{
if(m.indexOf(n[i])!==-1 )
{
return true;
}
return false;
}
}
function rot13(str) { // LBH QVQ VG!
var strArr = [];
for (var i = 0; i < str.length;i++) {
var char = str.charCodeAt(i) - 13;
strArr.push(String.fromCharCode(char));
}
return strArr;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
false
@eyesore- and this one:
function mutation(arr) {
var m=arr[0].toLowerCase();
var n=arr[1].toLowerCase();
for(var i=0;i<n.length;i++)
{
if(m.indexOf(n[i])!==-1 )
{
return true;
}
return false;
}
}
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
var go;
if( myObj.hasOwnProperty(checkProp) == true){
go = myObj.checkProp;
}else{
return "Not Found";
}
return go;
}
// Test your code by modifying these values
checkObj("gift");
function mutation(arr) {
var m=arr[0].toLowerCase();
var n=arr[1].toLowerCase();
for(var i=0;i<n.length;i++)
{
if(m.indexOf(n[i])!==-1 )
{
return true;
}
return false;
}
}
+ 13
in charcode
for(var i=0;i<n.length;i++)
{
// n[i] = 'h'
// if indexOf 'h' does not equal -1
// 'h' is in m so it does not equal -1
if(m.indexOf(n[i])!==-1 )
{
// since 'h' is in m
// function returns true and it does not check anything else
return true;
}
return false;
}
}
mutation(['hello', 'hye'])
n[i]
is not in m
then return false. If the loop is not and it never returned then you should return true
Hi guys, can anybody tell me what 'Everything Be True' challenge's problem means? "Check if the predicate (second argument) is truthy on all elements of a collection (first argument).
Remember, you can access object properties through either dot notation or [] notation."
return true
outside of the loop so it can goes through all the letters
A
will be N
right? So when you input A
it will translate to N
by adding 13
in charCode. But in the opposite, if you input N
, it will translate to A
by subtract 13
in charCode.
A
, and thats 65. 65 -13 isn't a letter.
function mutation(arr) {
var m=arr[0].toLowerCase();
var n=arr[1].toLowerCase();
for(var i=0;i<n.length;i++)
{
if(m.indexOf(n[i])!==-1 )
{
return true;
}
return false;
}
}
if(m.indexOf(n[i]) < 0){
return false;
}
return true;
@fillopfy
if(m.indexOf(n[i])!==-1 )
{
return true;
this will stop the loop if the first letter is matched
if(m.indexOf(n[i]) === -1 )
{
return false;
function mutation(arr) {
var m=arr[0].toLowerCase();
var n=arr[1].toLowerCase();
for(var i=0;i<n.length;i++)
{
if(m.indexOf(n[i])<0 )
{
return false;
}
return true;
}
}
for (var i=0; i<n.length; i++){
if (m.indexOf(n[i]) < 0){
return false;
}
}
return true;
}
fillopfy sends brownie points to @longnt80 and @willcoxdev and @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 250 | @willcoxdev |http://www.freecodecamp.com/willcoxdev
:cookie: 95 | @eyesore- |http://www.freecodecamp.com/eyesore-
:cookie: 292 | @longnt80 |http://www.freecodecamp.com/longnt80
return
works
reduce
in case anyone wants to get real deep with JS
A
-> 65
-> 65+13 -> 78
-> N
N
-> 78
-> 78 -13 -> 65
-> A
//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
if(contacts[i].firstName === firstName) {
if(contacts[i].prop === prop) {
return contacts[i].prop;
} else return "No such property";
} else return "No such contact";
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "lastName");
contacts[i].prop
punyparker sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 293 | @longnt80 |http://www.freecodecamp.com/longnt80
prop
isn't really a direct property on the object
else return "No such contact";
- does this make sense in the for loop?
addTogether(2)(3)
if the call is this, how can I access to the second closure? arguments[1]would not access to (3)
@ankerpeet
if(contacts[i].prop === prop)
ask if this should be:
if(contacts[prop] === prop)
if it should why or why not?
what about:
if(contacts[prop] == prop)
ankerpeet sends brownie points to @wikiwiggs :sparkles: :thumbsup: :sparkles:
:cookie: 306 | @wikiwiggs |http://www.freecodecamp.com/wikiwiggs
function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
var ne =arr1.concat(arr2);
for(var i = 0; i < arr1.length;i++){
if(arr1.indexOf(ne[i]) >=0 && arr2.indexOf(ne[i]) ==-1)
newArr.push(ne[i]);
if(arr1.indexOf(ne[i]) ==-1 && arr2.indexOf(ne[i]) >=0)
newArr.push(ne[i]);
}
return newArr;
}
diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'https://wind-bow.glitch.me/twitch-ap/streams/freecodecamp?callback=?',
header: {'Client-ID': 'hs5elqgum44iq9qdg3a1a3ydpyp00b'},
success: function(data) {
console.log(data);
},
error: function(err) {
console.log("error");
}
});
});
I am getting an Access-Control-Allow-Oirigin header is present error. Can someone explain to me what I am doing wrong with this test call?
function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
var ne =arr1.concat(arr2);
for(var i = 0; i < arr1.length;i++){
if(arr1.indexOf(ne[i]) >=0 && arr2.indexOf(ne[i]) ==-1)
newArr.push(ne[i]);
if(arr1.indexOf(ne[i]) ==-1 && arr2.indexOf(ne[i]) >=0)
newArr.push(ne[i]);
}
return newArr;
}
diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);
@deuscode try this:
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'https://crossorigin.me/https://wind-bow.glitch.me/twitch-ap/streams/freecodecamp?callback=?',
header: {'Client-ID': 'hs5elqgum44iq9qdg3a1a3ydpyp00b'},
success: function(data) {
console.log(data);
},
error: function(err) {
console.log("error");
}
});
});
Read more:
https://crossorigin.me/
function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
var ne =arr1.concat(arr2);
for(var i = 0; i < arr1.length;i++){
if(arr1.indexOf(ne[i]) >=0 && arr2.indexOf(ne[i]) ==-1)
newArr.push(ne[i]);
if(arr1.indexOf(ne[i]) ==-1 && arr2.indexOf(ne[i]) >=0)
newArr.push(ne[i]);
}
return newArr;
}
diffArray(["andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);
@masaki1223
here's the exmaple:
function makeAdder(x) {
return function(y) {
return x + y;
};
}
var add5 = makeAdder(5);
var add10 = makeAdder(10);
console.log(add5(2)); // 7
console.log(add10(2)); // 12
you can see add5(2)
is exactly makeAdder(5)(2)
ne[i]
no matter what
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'https://crossorigin.me/https://wind-bow.glitch.me/twitch-ap/streams/freecodecamp?client_id=hs5elqgum44iq9qdg3a1a3ydpyp00b?callback=?',
success: function(data) {
console.log(data);
},
error: function(err) {
console.log("error");
}
});
});
```function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
var ne =arr1.concat(arr2);
for(var i = 0; i < arr1.length;i++){
if(arr1.indexOf(ne[i]) != -1&& arr2.indexOf(ne[i]) ==-1)
newArr.push(ne[i]);
if(arr1.indexOf(ne[i]) ==-1 && arr2.indexOf(ne[i]) != -1)
newArr.push(ne[i]);
}
return newArr;
}
```
```function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.
var ne =arr1.concat(arr2);
for(var i = 0; i < arr1.length;i++){
if(arr1.indexOf(ne[i]) != -1&& arr2.indexOf(ne[i]) ==-1)
newArr.push(ne[i]);
if(arr1.indexOf(ne[i]) ==-1 && arr2.indexOf(ne[i]) != -1)
newArr.push(ne[i]);
}
return newArr;
}```
ankerpeet sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5613 | @manish-giri |http://www.freecodecamp.com/manish-giri
function addTogether(x) {
return function(y){
return x+y;
};
var newArr=[].slice.apply(arguments);
var result=newArr[0]+newArr[1];
for(var i=0; i<newArr.length; i++){
if(typeof newArr[i]!=='number'){
result=undefined;
break;
}
}
return result;
}
var sumTwoAnd = addTogether(2);
sumTwoAnd(3);
addTogether(2,3);
I want to make this work, but i dont know how to. Any help? How can I put another function in addTogether function?
ne
?
filter
from scratch so you know it inside and out?
deuscode sends brownie points to @wikiwiggs :sparkles: :thumbsup: :sparkles:
:cookie: 307 | @wikiwiggs |http://www.freecodecamp.com/wikiwiggs
addTogether(2, 3)
: this case arguments.length
is more than 1addTogether(2)(3)
: this case arguments.length
is 1if
to check destroyer([1, 2, 3, 1, 2, 3], 2, 3);
How do I reference the 2 and the 3 at the end in a function since it not in the array
arguments
codeastor sends brownie points to @whackdev :sparkles: :thumbsup: :sparkles:
:cookie: 278 | @whackdev |http://www.freecodecamp.com/whackdev
willcoxdev sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 294 | @longnt80 |http://www.freecodecamp.com/longnt80
function destroyer(arr) {
for(var i=0; i<arr.length;i++){
for(var j=1; j<(arguments.length); j++){
if (arr[i].toString.indexOf(arguments[j]) >=0){
arr.splice(i,1);
}
}
}
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
var movies = [
{
title: 'Troy',
rating: 5,
hasWatched: true
},
{
title: 'Alien: Covenant',
rating: 4.5,
hasWatched: true
},
{
title: 'Wonder Woman',
rating: 4.5,
hasWatched: false
},
{
title: 'Mad Max',
rating: 4,
hasWatched: true
}
];
for (var i = 0; i < movies.length; i++) {
if (movies[i].hasWatched === false) {
console.log('You have not seen ' + movies[i].title + ' - ' + movies[i].rating + ' stars');
} else {
console.log('You have seen ' + movies[i].title + ' - ' + movies[i].rating + ' stars')
}
}
this
would refer to the object window outside of an object.
for (var i = 0; i < movies.length; i++) {
if (this[i].hasWatched === false) {
console.log('You have not seen ' + thisi].title + ' - ' + this[i].rating + ' stars');
} else {
console.log('You have seen ' + this[i].title + ' - ' + this[i].rating + ' stars')
}
}
this
refers to the window
object not for the movies
object.
this
works inside constructors. Than it refers to the current object.
window
object.
traekwells sends brownie points to @ivancsicsmarkus :sparkles: :thumbsup: :sparkles:
:cookie: 511 | @ivancsicsmarkus |http://www.freecodecamp.com/ivancsicsmarkus
$(document).ready(function(){
$('.carousel').carousel();
});
why is this
return (arguments[1].toString()).indexOf(value);
Not the same as
var a1 = arguments[1].toString();
return a1.indexOf(value);
arguments
is not an array. It is just array-like. Sometimes it behaves strangely, like above.
function reduce(collection, iterator, accumulator) {
var accumUndefined = arguments.length < 3
collection.forEach(function(item){
if(accumUndefined) {
accumUndefined = false
accumulator = item
} else {
return accumulator = iterator(accumulator, item)
}
})
return accumulator
}
function factorial(num){
var result = 1;
for (var i=1; i<num; i++){
result *= i;
}
return result;
}
factorial(5);
sort
that is one everyone takes pride in, but I think the majority use a radix sort.
amelink sends brownie points to @willcoxdev :sparkles: :thumbsup: :sparkles:
:cookie: 252 | @willcoxdev |http://www.freecodecamp.com/willcoxdev
function destroyer(arr) {
var array = arguments[0];
var a1 = arguments[1].toString();
var a2 = arguments[2].toString();
array = array.filter(function(value){
return a1.indexOf(value);
});
array = array.filter(function(value){
return a2.indexOf(value);
});
return array;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
[1,2,3].indexOf("1")
array = array.filter(function(value){
return arguments[1].indexOf(value);
but this doenst work
return arguments[i].indexOf(value);
[a1, a2].indexOf(value)
destroyer([1, 2, 3,4, 5, 6], 7, 8);
wait so is the first arguement [1,2,3,4,5,6] and second 7 and the thrid 8 ordestroyer([1, 2, 3,4, 5, 6], 7, 8);
// [1, 2, 3,4, 5, 6] = 1
// 7 = 2
// 8 = 3
var array = [];
for (var i=1; i<arr.length; i++){
array.push(arguments[i]);
}
arr
is the same as arguments[0]
var filter = function(collection, test) {
var result = []
collection.forEach(function(item) {
if( test(item) ){
result.push(item)
}
})
return result
}
var map = function(collection, iterator) {
var result = []
collection.forEeach(function(item) {
result.push(iterator(item))
})
return result
}
function destroyer(arr) {
var array = [];
for (var i=1; i<arguments.length; i++){
array.push(arguments[i]);
}
for (var j=0;j<array.length;j++){
array = array.filter(function(value){
return array[j].indexOf(value);
});
}
return array;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
I got told not to make a a function within a loop
j
loop.
arr
and indexOf iterates array
.
ok I still dont get why this wont work
function destroyer(arr) {
var kill = [];
for (var i=1; i<arguments.length; i++){
kill.push(arguments[i]);
}
arr = arr.filter(function(value){
return kill.indexOf(value);
});
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
this is returning [1,3,1,3]
My understanding is that it should use both values stored in kill but it only seems to be usings the first
value
is found on kill
, and true otherwise.
function destroyer(arr) {
var kill = [];
for (var i=1; i<arguments.length; i++){
kill.push(arguments[i]);
}
arr = arr.filter(function(value){
kill.push(value);
});
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
function destroyer(arr) {
var kill = [];
for (var i=1; i<arr.length; i++){
kill.push(arr[i]);
}
arr = arr.filter(function(value){
kill.push(value);
});
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
-1
. Then it works.
function destroyer(arr) {
var kill = [];
for (var i=1; i<arguments.length; i++){
kill.push(arguments[i]);
}
arr = arr.filter(function(value){
if (kill.indexOf(value) >= 0){
return false;
}
else{
return true;
}
});
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Ok I did it. Now to fully understand
return kill.indexOf(value)===-1;
is simpler.
arguments
is a special keyword. It evaluates to an array-like object that holds all the passed arguments.
mantenn sends brownie points to @eyesore :sparkles: :thumbsup: :sparkles:
:warning: @eyesore's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
return kill.indexOf(value)===-1;
returns only when the index isnt found?
willcoxdev sends brownie points to @mantenn and @eyesore- and @wikiwiggs :sparkles: :thumbsup: :sparkles:
:cookie: 152 | @mantenn |http://www.freecodecamp.com/mantenn
:cookie: 96 | @eyesore- |http://www.freecodecamp.com/eyesore-
:cookie: 308 | @wikiwiggs |http://www.freecodecamp.com/wikiwiggs
-1
, it means is it not found?
.
having issues with CORS and my codepen coming from http... any way to change codepen to https? I thought it already was but I'm getting this error:
(Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://codepen.io" from accessing a cross-origin frame.)
and this error:
(XMLHttpRequest cannot load https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=. The 'Access-Control-Allow-Origin' header has a value 'https://s.codepen.io' that is not equal to the supplied origin. Origin 'http://s.codepen.io' is therefore not allowed access.)
$(document).ready(function(){
$("#newQuote").on("click", function(){
$.getJSON("https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en", function(json){
$(".message").html(JSON.stringify(json));
});
});
});
There's another person on here that got in a huge argument with me about semicolons.
willwaymel sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1677 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
willwaymel sends brownie points to @mantenn :sparkles: :thumbsup: :sparkles:
:cookie: 154 | @mantenn |http://www.freecodecamp.com/mantenn
@eyesore- hey @MANTENN said you might know what to do about this...
...
having issues with CORS and my codepen coming from http... any way to change codepen to https? I thought it already was but I'm getting this error:
(Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://codepen.io" from accessing a cross-origin frame.)
and this error:
(XMLHttpRequest cannot load https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=. The 'Access-Control-Allow-Origin' header has a value 'https://s.codepen.io' that is not equal to the supplied origin. Origin 'http://s.codepen.io' is therefore not allowed access.)
willwaymel sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
:cookie: 97 | @eyesore- |http://www.freecodecamp.com/eyesore-
col s12 m6
var potato = something
, something it is assigned to potato
potato
your dummy variable?
willwaymel sends brownie points to @mantenn and @eyesore- :sparkles: :thumbsup: :sparkles:
:warning: willwaymel already gave eyesore- points
:warning: willwaymel already gave mantenn points
https://api.forismatic.com/api/1.0/?method=getQuote&format=jsonp&lang=en&jsonp=?
and your browser devtools console shows more than the codepen console
potato
because you are afraid of grain lectins?
function repeatStringNumTimes(str, num) {
// repeat after me
for(var i=0;i<num;i++)
{
str+=str;
}
return str;
}
repeatStringNumTimes("abc", 3);
kreuel sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1678 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
str+=str;
doubles the amount of added strings.
var array = str.split("");
var numArray = [];
numArray.push(array.charCodeAt(1));
result += str;
would add it once.
str.charCodeAt(1)
?
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0;i < contacts.length; i++){
if(contacts[i].firstName && contacts[i].hasOwnProperty(prop)){
return contacts[i].prop;
}
}
// Only change code above this line
}
what I am dooing wrong ??
str
? string
str
is what?
function rot13(str) { // LBH QVQ VG!
var array = str.split("");
var numArray = [];
numArray.push(str.charCodeAt(1));
return str;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
1. you need a loop to pick each objects in the contacts array
1.1 in the loop you need to
1.1.1 check if the objects picked has the firstName property equal to the firstName parameter
1.1.1.1 you need to check if it has a property prop
return the value of prop in the object
1.1.1.2 return no such property if 1.1.1.1 is false
2. when your loop is done looking through contacts return no such contact
str
from the spaces not as characters
var array = str.split(" ");
@Lumexralph ```
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0;i < contacts.length; i++){
if(contacts[i].firstName == firstName ){
if(contacts[i].hasOwnProperty(prop)){
return contacts[i].prop;
}
else {
return "No such property";
}
}
}
return "No such property";
```
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0;i < contacts.length; i++){
if(contacts[i].firstName == firstName ){
if(contacts[i].hasOwnProperty(prop)){
return contacts[i].prop;
}
else {
return "No such property";
}
}
}
return "No such property";
function rot13(str) { // LBH QVQ VG!
var numArray = [];
for(var i=0;i<str.length;i++){
if((str.charCodeAt(i)) !== 32){
numArray.push(str.charCodeAt(i)-13);
}
else{
numArray.push(str.charCodeAt(i));
}
}
var finalStr = '';
for (var j=0;j<numArray.length;j++){
finalStr += String.fromCharCode(numArray[j]);
}
return finalStr;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
>>>> F8EE C5DE CAM6 (meant to return FREE CODE CAMP)
.prop
looks for property key "prop"
, not the key stored in parameter prop
.
reactorboy sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4113 | @masd925 |http://www.freecodecamp.com/masd925
A
will become N
, and N
will translated to A
N
become A
A
-> 65 -> 65+13 -> 78 -> N
wikiwiggs sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 295 | @longnt80 |http://www.freecodecamp.com/longnt80
function rot13(str) { // LBH QVQ VG!
var numArray = [];
for(var i=0;i<str.length;i++){
if((str.charCodeAt(i)) !== 32 && (str.charCodeAt(i)) >= 78){
numArray.push(str.charCodeAt(i)-13);
}
else if((str.charCodeAt(i)) !== 32 && (str.charCodeAt(i)) < 78){
numArray.push(str.charCodeAt(i)+13);
}
else if((str.charCodeAt(i)) === 32){
numArray.push(str.charCodeAt(i));
}
}
var finalStr = '';
for (var j=0;j<numArray.length;j++){
finalStr += String.fromCharCode(numArray[j]);
}
return finalStr;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
32
(you should only care if the character is A-Z
or something else). Just test if the charcode is between 65-90 and then if it is on the lower or top half.
function rot13(str) { // LBH QVQ VG!
var numArray = [];
for(var i=0;i<str.length;i++){
if((str.charCodeAt(i)) <= 90 && (str.charCodeAt(i)) >= 78){
numArray.push(str.charCodeAt(i)-13);
}
else if((str.charCodeAt(i)) >= 65 && (str.charCodeAt(i)) < 78){
numArray.push(str.charCodeAt(i)+13);
}
else{
numArray.push(str.charCodeAt(i));
}
}
var finalStr = '';
for (var j=0;j<numArray.length;j++){
finalStr += String.fromCharCode(numArray[j]);
}
return finalStr;
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
str
to uppercase first
str = str.toUpperCase();
under the function at the top
willcoxdev sends brownie points to @masd925 and @longnt80 and @wikiwiggs and @mantenn :sparkles: :thumbsup: :sparkles:
:cookie: 170 | @mantenn |http://www.freecodecamp.com/mantenn
:cookie: 296 | @longnt80 |http://www.freecodecamp.com/longnt80
:cookie: 309 | @wikiwiggs |http://www.freecodecamp.com/wikiwiggs
:star2: 4114 | @masd925 |http://www.freecodecamp.com/masd925
@Masd925
one remainder operation
I can't think of the use for this in this case? Why?
cc%26+65
will do the charcode mapping.
cc%26
?
cc
, once it has been tested to be on the range A-Z cc>64 && cc<91
function rot13(str) {
return str.split("").map(function(char){
var cc = char.charCodeAt(0);
return (cc>64 && cc<91) ? String.fromCharCode(cc%26+65) : char;
}).join("");
}
longnt80 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4115 | @masd925 |http://www.freecodecamp.com/masd925
return (cc>64 && cc<91) ? String.fromCharCode(cc%26+65) : char;
, I know the ?
and :
create an if statement. But what is the term for it or can you give me a link to read about it?
longnt80 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: longnt80 already gave masd925 points
function myLocalScope() {
'use strict';
var myVar = "Hello";
console.log(myVar);
}
myLocalScope();
// Run and check the console
// myVar is not defined outside of myLocalScope
// Now remove the console log line to pass the test
console.log(myVar)
statement to immediately after myLocalScope();