17th
Sep 2017
Ellyria
@Ellyria
Sep 17 2017 00:29
Thanks for the video, @jimtryon. I'm loving it!
CamperBot
@camperbot
Sep 17 2017 00:29
ellyria sends brownie points to @jimtryon :sparkles: :thumbsup: :sparkles:
Nick Cleary
@Hijerboa
Sep 17 2017 00:33
@jimtryon beautiful video mate! Thank you!
CamperBot
@camperbot
Sep 17 2017 00:33
hijerboa sends brownie points to @jimtryon :sparkles: :thumbsup: :sparkles:
Long Nguyen
@longnt80
Sep 17 2017 00:37
@jimtryon thanks :D
CamperBot
@camperbot
Sep 17 2017 00:37
longnt80 sends brownie points to @jimtryon :sparkles: :thumbsup: :sparkles:
Nick Cleary
@Hijerboa
Sep 17 2017 00:37
Why is the following not detecting if any of the item's values is NaN (as in the thing is quite literally "NaN")
``````function truthCheck(collection, pre) {
var first = "";
var second = "";
var thingToLookFor;
for(i=0;i<collection.length;i++){
thingToLookFor = pre;
if(collection[i][thingToLookFor] == undefined || collection[i][thingToLookFor] == NaN || collection[i][thingToLookFor] == ""){
return false;
} else if(collection[i][thingToLookFor] != first && collection[i][thingToLookFor] != second){
if(first == ""){
first = collection[i][thingToLookFor];
} else if (second == ""){
second = collection[i][thingToLookFor];
} else if (collection[i][thingToLookFor] == true){
first = true;
}else{
return false;
}
}
}
return true;
}``````
my code doesn't work for the final test case
Long Nguyen
@longnt80
Sep 17 2017 00:48
@Hijerboa if `collection[i][thingToLookFor]` is `NaN` then you have `NaN == NaN` which is `false`
because NaN is not equal to anything, even itself
Greg Duncan
@GregatGit
Sep 17 2017 00:49
@Hijerboa I think you may have over thought this one - your answer could be simpler
Nick Cleary
@Hijerboa
Sep 17 2017 00:50
@longnt80 so would you test by using != NaN?
Long Nguyen
@longnt80
Sep 17 2017 00:51
I think you should use the function `isNaN`
Nick Cleary
@Hijerboa
Sep 17 2017 00:51
@longnt80 wouldn't that disqualify anything which has numbers?
Long Nguyen
@longnt80
Sep 17 2017 00:52
ah, yes, let me see
Nick Cleary
@Hijerboa
Sep 17 2017 00:53
@longnt80 there is one test case with includes numbers. While that test case is supposed to return false, not all possible entered values which contain numbers would necessarily be false
Nick Cleary
@Hijerboa
Sep 17 2017 01:04
@longnt80 I tried throwing an isNan function in there... still doesn't work
here's my current code:
``````function truthCheck(collection, pre) {
var first = "";
var second = "";
for(i=0;i<collection.length;i++){
if(collection[i][pre] == undefined || collection[i][pre] == ""){
return false;
} else if (isNaN(collection[i][pre] == false)) {
return false;
} else if(collection[i][pre] != first && collection[i][pre] != second){
if(first == ""){
first = collection[i][pre];
} else if (second == ""){
second = collection[i][pre];
} else if (collection[i][pre] == true){
first = true;
}else{
return false;
}
}
}
return true;
}``````
Gersho
@Gersho
Sep 17 2017 01:05
wow that's a lot of ifs, what are you trying to accomplish ?
Nick Cleary
@Hijerboa
Sep 17 2017 01:05
@Gersho haha
Long Nguyen
@longnt80
Sep 17 2017 01:06
@Hijerboa you can use `Boolean(collection[i][pre])`
Nick Cleary
@Hijerboa
Sep 17 2017 01:07
@longnt80 is Boolean a function?
Long Nguyen
@longnt80
Sep 17 2017 01:07
yes
basically it will check all falsy values
Gersho
@Gersho
Sep 17 2017 01:07
you could reduce greatly the number of if by adding more ||
Nick Cleary
@Hijerboa
Sep 17 2017 01:08
turns out it is....
using that solves the problem I came here with, but broke several other things I had fixed earlier
gosh darned
Long Nguyen
@longnt80
Sep 17 2017 01:10
@Hijerboa did you do the Falsy Bouncer?
Nick Cleary
@Hijerboa
Sep 17 2017 01:11
Using the Boolean function works for that, but breaks other things
Long Nguyen
@longnt80
Sep 17 2017 01:11
@Hijerboa no it should works for all cases
i just tested it
Nick Cleary
@Hijerboa
Sep 17 2017 01:12
Heres the current code; it doesn't work for the first, fifth, and sixth test cases.
``````function truthCheck(collection, pre) {
var first = "";
var second = "";
for(i=0;i<collection.length;i++){
if(collection[i][pre] == undefined || collection[i][pre] == ""){
return false;
} else if (Boolean(collection[i][pre])) {
return false;
} else if(collection[i][pre] != first && collection[i][pre] != second){
if(first == ""){
first = collection[i][pre];
} else if (second == ""){
second = collection[i][pre];
} else if (collection[i][pre] == true){
first = true;
}else{
return false;
}
}
}
return true;
}``````
Long Nguyen
@longnt80
Sep 17 2017 01:12
@Hijerboa that's not how you do it
Nick Cleary
@Hijerboa
Sep 17 2017 01:12
which makes no sense, it was working before I added that Boolean function
@longnt80 welp
Gersho
@Gersho
Sep 17 2017 01:13
(Boolean(collection[i][pre]))
what do you expect from this line ?
Long Nguyen
@longnt80
Sep 17 2017 01:13
you only need to do Boolean without other `if`s

@Hijerboa so replace all these:

``````if(collection[i][pre] == undefined || collection[i][pre] == ""){
return false;
} else if (Boolean(collection[i][pre])) {
return false;
} else if(collection[i][pre] != first && collection[i][pre] != second){
if(first == ""){
first = collection[i][pre];
} else if (second == ""){
second = collection[i][pre];
} else if (collection[i][pre] == true){
first = true;
}else{``````

with the `Boolean(collection[i][pre])`

Nick Cleary
@Hijerboa
Sep 17 2017 01:14
seriously?
its that simple?
Long Nguyen
@longnt80
Sep 17 2017 01:14
yeah
actually, you need to use `!Boolean(collection[i][pre])`
Gersho
@Gersho
Sep 17 2017 01:14
on mine i used 2 if (one of them having quite a lot of || ) (within a for loop)
Long Nguyen
@longnt80
Sep 17 2017 01:14
to get the `false` value
yeah, if you don't use Boolean, you should only need 2 `if`s like @Gersho said
Gersho
@Gersho
Sep 17 2017 01:17
i wonder if it can be worked with a
``return collection.every( //do magic //);``
Nick Cleary
@Hijerboa
Sep 17 2017 01:17
`````` function truthCheck(collection, pre) {
for(i=0;i<collection.length;i++){
if(Boolean(collection[i][pre]) !== true){
return false;
}
}
return true;
}``````
what is programmikng
@Gersho @longnt80 thank you! You guys are amazing
CamperBot
@camperbot
Sep 17 2017 01:18
hijerboa sends brownie points to @gersho and @longnt80 :sparkles: :thumbsup: :sparkles:
Nick Cleary
@Hijerboa
Sep 17 2017 01:18
Now I'm just going to go bang my head against the wall
Gersho
@Gersho
Sep 17 2017 01:19
i didn't know much about what evaluates as true/false back when i did that one, mine's like that xD
``````
function truthCheck(collection, pre) {
// Is everyone being true?

for (i=0; i<collection.length; i++){

if (!collection[i].hasOwnProperty(pre)){
return false;
} else {

if (collection[i][pre] === null
|| collection[i][pre] === undefined
|| collection[i][pre].toString() == "NaN"
||  collection[i][pre] === 0
|| collection[i][pre] === "" ){
return false;
}

}

}

return true;
}``````
Nick Cleary
@Hijerboa
Sep 17 2017 01:20
@Gersho how does your code detect if there are more than two values used?
Gersho
@Gersho
Sep 17 2017 01:20
what do you mean more than 2 values ?
Nick Cleary
@Hijerboa
Sep 17 2017 01:21
isn't that the point of the excerise? to detect if more than two values are used? Like a sort of crappy binary?
or did I just code something completely different than necessary?
Gersho
@Gersho
Sep 17 2017 01:22
i don't understand the question, my code checks for every item in the array is if passes the required test (having a value for specified element), and returns true if nothing wrong was detected
Nick Cleary
@Hijerboa
Sep 17 2017 01:23
@Gersho I figured out the answer to my question: I misread the "prompt" and was programming to solve a completely different problem
Gersho
@Gersho
Sep 17 2017 01:23
how did you manage to solve it ? xD
Nick Cleary
@Hijerboa
Sep 17 2017 01:24
I was trying to see if there was more than two values returned for each thing that was tested for. So for instance, if age was the thing to look for than, ages of (1,2,3, and 4) would return false, but (1,2,1,2,2,2,1 and 1) would return true
I solved the problem in my original code I posted here
or at least I think I did... Since I was testing for the wrong thing lol
Gersho
@Gersho
Sep 17 2017 01:26
lol
check this out :D
``````
function truthCheck(collection, pre) {
// Is everyone being true?

return collection.every(function(elem){
return Boolean(elem[pre]);
});
}``````
thanks @Hijerboa @longnt80 for sparkling the idea
CamperBot
@camperbot
Sep 17 2017 01:29
gersho sends brownie points to @hijerboa and @longnt80 :sparkles: :thumbsup: :sparkles:
korzo
@korzo
Sep 17 2017 01:30
@Gersho you can return directly elem[pre]
javascript will convert it to bool automatically
``````function truthCheck(collection, pre) {
return collection.every(el => el[pre]);
}``````
Gersho
@Gersho
Sep 17 2017 01:31
thanks @korzo is that a behavior specific to every ?
CamperBot
@camperbot
Sep 17 2017 01:31
gersho sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
korzo
@korzo
Sep 17 2017 01:32
@Gersho for every function expecting bool return value, e.g. filter
Gersho
@Gersho
Sep 17 2017 01:32
ok
Duyali
@Duyali
Sep 17 2017 01:55
hello,everybody.i'm new here.
Gersho
@Gersho
Sep 17 2017 01:55
welcome
Duyali
@Duyali
Sep 17 2017 01:56
thanks
how long do you learn this?and how long i need to good at this i want to know
Ellyria
@Ellyria
Sep 17 2017 02:16
Welcome, newcomers!
Not to worry about the JavaScript, @Duyali. This course will help you with it. As far as how long... that depends on the person. Everyone is different. Some people can breeze right through, others have to take their time or go over the information more than once. Also, it depends on how likely you are to "go down the rabbit hole" elsewhere whenever you get the chance when researching something or finding out about a cool site or interesting video or lecture, etc.
Ellyria @Ellyria is easily seduced by rabbit holes.
silver537
@silver537
Sep 17 2017 02:59
Or just truthCheck
Sep 17 2017 04:06
writing abstract code
Perry Tran
@perrytran242
Sep 17 2017 04:43
``
Sandip Shrestha
@saninmersion
Sep 17 2017 06:32
This is my weather app, can some one suggest me simple ways to make a toggle button for my C/F toggle? also suggest me some design aspects. having trouble making it look good.
https://codepen.io/saninmersion/full/BWwvpv/
Gersho
@Gersho
Sep 17 2017 06:34
@saninmersion try merging the C/F button ?
make 1 button, when clicked, on top of changing what it already does, make it change the content of the button too
Sandip Shrestha
@saninmersion
Sep 17 2017 06:36
@Gersho that is a good idea
@Gersho I am going to give it a try. thank you.
CamperBot
@camperbot
Sep 17 2017 06:36
saninmersion sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
Sep 17 2017 06:48
it reminds me of true/false "D
piteto
@piteto
Sep 17 2017 07:06
``````\$(".tempC").html(`\${info.main.temp}°C`);
\$(".tempF").html(`\${Math.floor(info.main.temp * (9 / 5) + 32)}°F`).hide();
\$("#convert").on("click", () => \$('.tempF, .tempC').toggle('hide'));``````
Add the temperature for both to your page. Hide one, then toggle both on click
Sep 17 2017 07:59
whoever came with concept of NaN f!
you can hate js in many many ways , if your from ES 5 world :D
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:05
I have a question about the dungeon crawler
Is it allowed to re enter an old level?
say im at level 1, i dont kill all the monsters and go to level 2, will it be allowed to re enter level 1 again ?
Sep 17 2017 08:08
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:09
im asking if it that is a required thing
because technically you might not be able to win the game if you dont kill x monsters in a level
Sep 17 2017 08:13
if you can allow him to next level its a win :)
he can enter any level :) curr-1 curr curr+1 in the order
where curr , is current level
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:15
lol
Sep 17 2017 08:16
?
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:16
that really depends on the project structure
you'd have to generate matrices and keep their states updated for that
The project on FCC doesn't do this
its not a user story either i guess i'll do it without that
Sep 17 2017 08:17
you think a lot :)
well mistakes are allowed :+1:
for your question , sorry FCC no idea what you do but i wont need matrices its too costly to keep it ! you may cry i need memory!
Manish Giri
@Manish-Giri
Sep 17 2017 08:24
@abhinav-thinktank :wave:
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:25
@Manish-Giri :wave:
Sep 17 2017 08:25
[O.O]
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:26
@Manish-Giri aisa lagraha hai puri zindagi mehnat kari hai
@Manish-Giri :P
Manish Giri
@Manish-Giri
Sep 17 2017 08:26
lol
bilkul
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:26
ab bas phd nikalni hai
Manish Giri
@Manish-Giri
Sep 17 2017 08:26
usse pehle bacche ki jaan nikal jayegi
lol
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:26
lol
@Manish-Giri dungeon crawler kara hai?
Manish Giri
@Manish-Giri
Sep 17 2017 08:27
abi start hi kia hai bas
dimaag ki dahi wala project hai
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:27
sahi me
purani level jaana allowed hai?
uske lie
Manish Giri
@Manish-Giri
Sep 17 2017 08:28
real life mein allowed hota hai
but mai nai kar raha
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:28
hmm
matrices?
Manish Giri
@Manish-Giri
Sep 17 2017 08:29
waise bhi zindagi mai bohot jhamele hai, wapis old level nahi chahie
yep
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:29
lol
sahi baat
Manish Giri
@Manish-Giri
Sep 17 2017 08:29
udemy pe ek naya react course aya hai
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:29
kaunsa
grider ka hai?
Manish Giri
@Manish-Giri
Sep 17 2017 08:29
wait kar raha price kam hone ka
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:29
yaar ye acha banda hai
Manish Giri
@Manish-Giri
Sep 17 2017 08:30
complete react dev version 2
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:30
nice
Manish Giri
@Manish-Giri
Sep 17 2017 08:30
version 1 thoda outdated hai
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:30
uska node ka kiya hai
bahut acha laga
Manish Giri
@Manish-Giri
Sep 17 2017 08:30
v1 and v2 dono lia hai
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:30
hmm
mujhe grider ka itna pasand nahi aya
Manish Giri
@Manish-Giri
Sep 17 2017 08:30
but filhaal v1 ke sequelize wale step mein atka hu
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:30
pura project to wo likhdeta hai
Manish Giri
@Manish-Giri
Sep 17 2017 08:30
han correct
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:30
mead challenges deta hai to seekhte ho
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:32
@Manish-Giri price gire to batana ill also get it
redux ke lie chahie basically
Manish Giri
@Manish-Giri
Sep 17 2017 08:36
coool
waha udemy mein rupees mein list hota hai kya?
usually kitna hota hai price per course
@abhinav-thinktank
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:44
450
@Manish-Giri
lol
bahut cheap
Manish Giri
@Manish-Giri
Sep 17 2017 08:44
fk
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:44
waha mehenga haina?
Manish Giri
@Manish-Giri
Sep 17 2017 08:45
450 mein dominoes ki pizza aa jati hai mast wali
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:45
lol
Manish Giri
@Manish-Giri
Sep 17 2017 08:45
yup
right now it's \$15
almost 1000 rs
bc
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:45
hmm
\$10 tak girta haina?
Manish Giri
@Manish-Giri
Sep 17 2017 08:46
yup
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:46
yaha to log torrent bhi karlete hai courses
lol
dost ne pura treehouse karlia tha
Manish Giri
@Manish-Giri
Sep 17 2017 08:47
wow
here i'm paying \$9 monthly for treehouse
bc
Abhinav Mishra
@abhinav-m
Sep 17 2017 08:48
lol
Zac Cassini
@zcassini
Sep 17 2017 10:47
i'll do smalltalk lessons for \$8 a month
thats a good savings on treehouse
WAINGOR
@WAINGOR
Sep 17 2017 12:29
Hi all, I am currently at steamRoller (intermediate algo challenges)
``````
function steamrollArray(arr) {
// I'm a steamroller, baby
while (arr.some(function(element){
return Array.isArray(element);
})) {
arr = [].concat(...arr);
};

}

steamrollArray([1, [2], [3, [[4]]]]);``````
does anybody know why this is incorret?
incorrect*
korzo
@korzo
Sep 17 2017 12:33
@WAINGOR Because you always concat whole array instead of just element
WAINGOR
@WAINGOR
Sep 17 2017 12:37
on which line?
I dont think that is correct.. I am using the spread operator which only takes the value OUT of an array
korzo
@korzo
Sep 17 2017 12:39
@WAINGOR Oh, sorry, You forgot to return arr
WAINGOR
@WAINGOR
Sep 17 2017 12:40
hahahahah
your'e right, thanks @korzo
CamperBot
@camperbot
Sep 17 2017 12:40
waingor sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
korzo
@korzo
Sep 17 2017 12:40
@WAINGOR I edited my post and forgot to send it :)
@WAINGOR btw very nice solution . First time I see it :+1:
cowCrazy
@cowCrazy
Sep 17 2017 13:27
Asking out of curiosity, did anyone had problems with `setInterval`/`setTimeout` for the pomodoro clock project and the natural behavior of the browsers to ignore them while tab is out of focus if yes, what was the workaround you've used?
Tiago Correia
@tiagocorreiaalmeida
Sep 17 2017 13:33
@cowCrazy is that happening to you?
cowCrazy
@cowCrazy
Sep 17 2017 13:34
@tiagocorreiaalmeida yes, if I switch to another tab and then coming back to the tab with the pomodoro the the setInterval was suspended, and starts running again only when I come back
Tiago Correia
@tiagocorreiaalmeida
Sep 17 2017 13:39
do you have a codepen?
cowCrazy
@cowCrazy
Sep 17 2017 13:49
@tiagocorreiaalmeida yes
Tiago Correia
@tiagocorreiaalmeida
Sep 17 2017 13:51
post it here
cowCrazy
@cowCrazy
Sep 17 2017 13:55
Marc
@MWBauer
Sep 17 2017 13:59
arr.filter will filter out all the things you specify and make a new array of them, correct?
cowCrazy
@cowCrazy
Sep 17 2017 14:03
@MWBauer yes, if you work with it correctly ;)
Marc
@MWBauer
Sep 17 2017 14:04
Sure. I'm good with that.
Tiago Correia
@tiagocorreiaalmeida
Sep 17 2017 14:04
@cowCrazy that looks kinda strange
Marc
@MWBauer
Sep 17 2017 14:04
Now..how do I do that.
Tiago Correia
@tiagocorreiaalmeida
Sep 17 2017 14:04
so you call .filter
Marc
@MWBauer
Sep 17 2017 14:04
I'm trying to sort out the "" and null and such. So I would want to search for words and number, right?
Tiago Correia
@tiagocorreiaalmeida
Sep 17 2017 14:04
and inside if you write a statmeent
Marc
@MWBauer
Sep 17 2017 14:04
I tried a regex
Tiago Correia
@tiagocorreiaalmeida
Sep 17 2017 14:04
if that's true the value gets pushed into the result
Marc
@MWBauer
Sep 17 2017 14:05
I want it to find the words and numbers to pull them out and make a new array.
Sandip Shrestha
@saninmersion
Sep 17 2017 14:09
@MWBauer instead of searching for numbers and words why dont you search for falsy values (null, "", undefined, 0, and so on)
Marc
@MWBauer
Sep 17 2017 14:09
Nvm. I gotta go for now.
cowCrazy
@cowCrazy
Sep 17 2017 14:09
@tiagocorreiaalmeida I thought it is weird too but it is JS natural behavior for browsers to save resources..... in stack overflow people suggested webworkers or working with the Date object, but I was wondering how did others here dealt with it
cowCrazy
@cowCrazy
Sep 17 2017 14:25
@korzo :wave:
you know anything about the setInterval / setTimeout issues when a tab is out of focus?
korzo
@korzo
Sep 17 2017 14:27
@cowCrazy When tab is out of focus, it runs on lowest priority.
In your code, instead of relying on setTimeout/interval, you should store current time value at function invocation and then compare it on next invocation
@cowCrazy I you understand event loop, it means setInterval(fn, 1000) can be invoked every 10/30/60 seconds instead of every second
cowCrazy
@cowCrazy
Sep 17 2017 14:31
@korzo I have used that method with current time and I can catch up with the timer, but then I would still have the problem of starting a new iteration when the session is over....
Margaret Greaney
@greaneym
Sep 17 2017 14:36
hello, could someone please give me hint on how to do the caret symbol on a default view of the camp leaderboard. I've tried several things which did not work.
korzo
@korzo
Sep 17 2017 14:36
@cowCrazy You can use while loop subtract time for session and break
Margaret Greaney
@greaneym
Sep 17 2017 14:38
I've tried to absolutely position the caret in a span tag, tried a jsx condition statement on the map of the header, tried a new classname for the caret, tried inline style, but can't get it to work. Any pointers would be very appreciated.
Am using '\u2191' as the caret symbol.
korzo
@korzo
Sep 17 2017 14:39
@greaneym use pseudo class :before/:after and add to it
`content: " ▼";`
Margaret Greaney
@greaneym
Sep 17 2017 14:40
@korzo , so use this in a scss/css file and then use classname?
I've tried that, using before and after in the css, but it doesn't appear on refresh.
korzo
@korzo
Sep 17 2017 14:42
@greaneym yes, on click add class with js and then css
``````.classname:after {
content: " ▼";
}``````
If content is display:inline, it should work out of the box
Margaret Greaney
@greaneym
Sep 17 2017 14:43
@korzo, thanks I will try this suggestion.
CamperBot
@camperbot
Sep 17 2017 14:43
greaneym sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
cowCrazy
@cowCrazy
Sep 17 2017 14:44
@korzo but then wouldn't it work to hard for it? I mean with a while loop it is going to iterate a lot, or?
I have the feeling I am missing something with this challange..... could use here async await or something like that, but it feels like way to advanced for such a challange :worried:
Margaret Greaney
@greaneym
Sep 17 2017 14:48
@korzo, the arrow up or down displays with no problem onClick, but I'm asking, how do I get the default display to show the caret. I did try your suggestion but it does not display.
korzo
@korzo
Sep 17 2017 14:50
@cowCrazy I meant to use while loop for time difference when fn is invoked.
you can't rely on browser, so you have to calculate tme yourself.
For example Firefox can unload your tab, if is out of focus for long time.
async will not solve this either.
Margaret Greaney
@greaneym
Sep 17 2017 14:53
I will check back later and in mean time, keep searching for an answer.
korzo
@korzo
Sep 17 2017 14:54
@greaneym can I see your app somewhere?
Maybe I don't understand what your problem is.
Because it should work like this:
http://jsbin.com/caruvo/edit?html,css,js,output
cowCrazy
@cowCrazy
Sep 17 2017 14:56

@korzo I am afraid I am not sure what you mean by that.

``````var timeHide, timeShow, timePassed, timeLeft;

function handleVisibilityChange() {
if (document.hidden) {
timeHide = Date.now();
} else  {
timeShow = Date.now();
timePassed = (timeShow - timeHide);
console.log('time passed: ', timePassed);
min = +minutes.innerHTML;
sec = +seconds.innerHTML;
timeLeft = ((min * 60 + sec) * 1000) - timePassed;

minutes.innerHTML = Math.floor(timeLeft / 60000);
seconds.innerHTML = Math.ceil(timeLeft % 60000 / 1000);

timeHide = 0;
timeShow = 0;
}
}

That's what I use now, but as I said I don't see how to solve the case when the user isn't coming back to the tab after the session already ended

Leon Boehmer
@Mortuie
Sep 17 2017 15:00
Anyone free to help me with my last frontend project ?
korzo
@korzo
Sep 17 2017 15:05

@cowCrazy you have error on line 607
`iterationName.innerHTML = clock.getState().isSession? 'Session': 'Break';`

Uncaught TypeError: Cannot set property 'innerHTML' of null

cowCrazy
@cowCrazy
Sep 17 2017 15:08
@korzo you can ignore that.... it is just the minutes and seconds node on the DOM....
Now you can see here the full code
cowCrazy
@cowCrazy
Sep 17 2017 15:16
@korzo sorry I have to go, thanks anyhow, I'll get back to that later
CamperBot
@camperbot
Sep 17 2017 15:16
cowcrazy sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
Margaret Greaney
@greaneym
Sep 17 2017 15:17
@korzo, thanks for the link, but it does not contain an example of using a caret or utf code for a caret. the link to my pen, https://codepen.io/greaney/pen/WZbYwZ
CamperBot
@camperbot
Sep 17 2017 15:17
greaneym sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
api offline
Margaret Greaney
@greaneym
Sep 17 2017 15:20
I have to leave now but will try back later.
korzo
@korzo
Sep 17 2017 15:28
@cowCrazy see you. Let me know how it goes
Tiago Correia
@tiagocorreiaalmeida
Sep 17 2017 15:40
display: none;
}
need a littler help
when I have .projectos .project.active-project I want the header to dont display
im missing anything? or is not possible with css?
by this I mean when a class is active I dontwant the header to display
but I think im gonna be only avaible to do this torught js?
korzo
@korzo
Sep 17 2017 15:41
@greaneym so you want to display caret also on load?
Leon Boehmer
@Mortuie
Sep 17 2017 15:57
Anyone up for helping me with a js project :?
korzo
@korzo
Sep 17 2017 16:10
@Mortuie Which project?
firas omrane
@firou1925
Sep 17 2017 16:12
hello world
Leon Boehmer
@Mortuie
Sep 17 2017 16:13
I think I found a solution thanks!
Margaret Greaney
@greaneym
Sep 17 2017 17:20
@korzo, yes. I also tried to put in a function in the jsx onLoad() but that didn't work for me. If you have a suggestion about what to try, that would be great.
I have been looking at how people are adding emoji images on stack overflow and this looks like what I need to do as these are all unicode symbols. But so far I can't get the examples to work.
Margaret Greaney
@greaneym
Sep 17 2017 17:27
back later.
monkeyfingerz
@monkeyfingerz
Sep 17 2017 18:28

Shoot how do you format code on here again
korzo
@korzo
Sep 17 2017 18:29
`state.sortby === idx`
you should set state.sortby at startup for default value in getInitialState method
monkeyfingerz
@monkeyfingerz
Sep 17 2017 18:29

function smallestCommons(arr) {
var range = [];
if (arr[0]>arr[1]){
for(var i =arr[1]; i<=arr[0];i++){
range.push(i);
}
}else{
for(var j = arr[0]; j<=arr[1]; j++){
range.push(j);
}
}
var counter =1;
function works (){
for(var k = 0 ; k < range.length; k++){

``````  if( counter % range[k] !== 0){
counter++;
k=0;
}
}
return counter;``````

}
}

// test here
smallestCommons([1,5]);

korzo
@korzo
Sep 17 2017 18:29
@monkeyfingerz ```
monkeyfingerz
@monkeyfingerz
Sep 17 2017 18:29
whoops
korzo
@korzo
Sep 17 2017 18:29
@monkeyfingerz wrap your code with it
monkeyfingerz
@monkeyfingerz
Sep 17 2017 18:30
``````function smallestCommons(arr) {
var range = [];
if (arr[0]>arr[1]){
for(var i =arr[1]; i<=arr[0];i++){
range.push(i);
}
}else{
for(var j = arr[0]; j<=arr[1]; j++){
range.push(j);
}
}
var counter =1;
function works (){
for(var k = 0 ; k < range.length; k++){

if( counter % range[k] !== 0){
counter++;
k=0;
}
}
return counter;
}
}

// test here
smallestCommons([1,5]);``````
can someone take a look at my code and tell me why the counter isn't climbing
Moisés Man
@moigithub
Sep 17 2017 18:46
works is a function
where u calling it ? @monkeyfingerz
Joel Y.
@zapcannon99
Sep 17 2017 18:48

@monkeyfingerz
if counter is not changing at all, then the problem has to be with your if statement with counter in the conditional

so with this particular test case `smallestCommons([1,5])`, it seems that range[0] = 1
Counter = 1
1 % 1 = 0 which fails the conditional and never increments counter

At least that's what I read, I could be wrong, somebody can correct me

Thayyeb salim
@Thayyebsalim
Sep 17 2017 18:48
``````
function updateInventory(arr1, arr2) {
arr1.reduce(function(acc, curr) {
acc.push([ curr[0],curr[1] ]);
}, []);
}

// Example inventory lists
var curInv = [
[21, "Bowling Ball"],
[2, "Dirty Sock"],
[1, "Hair Pin"],
[5, "Microphone"]
];

var newInv = [
[2, "Hair Pin"],
[3, "Half-Eaten Apple"],
[67, "Bowling Ball"],
[7, "Toothpaste"]
];

updateInventory(curInv, newInv);``````
this shows acc not defined
any idea guys?
korzo
@korzo
Sep 17 2017 18:52
@Thayyebsalim you have to return acc
BrianWilliams28
@BrianWilliams28
Sep 17 2017 18:52
Can someone help? I cant figure out why my function is returning undefined.
``````let regex = /(\d{3}|\(\d{3}\))([0-9]{3}|-[0-9]{3})(\d{4}|-\d{4})/g;

function telephoneCheck(str) {
str = str.replace(/\s/g, '');
let test = regex.test(str);

if (str.length == 11 && str.charAt(0) == 1) {
str = str.slice(1);
if (test) {
return true;
}
} else if (str.length == 10 && test)
{
return true
} else
return false;
}

telephoneCheck("1 555 555 5555"); // should return true but returns undefined? =/
console.log(telephoneCheck("1 555 555 5555"));``````
korzo
@korzo
Sep 17 2017 18:53
@Thayyebsalim and also return from function
monkeyfingerz
@monkeyfingerz
Sep 17 2017 19:07
@Thayyebsalim well i think the problem is when your push into acc. Acc is not an array
Ronique Ricketts
@RoniqueRicketts
Sep 17 2017 19:07
@kumquatfelafel I hope I will be able to get it to a few mil
FlashHero
@FlashHero
Sep 17 2017 19:10
@BrianWilliams28 `regex` variable is outside the function, I don't think freecodecamp let you define global variables
monkeyfingerz
@monkeyfingerz
Sep 17 2017 19:12
``````function smallestCommons(arr) {
//noprotect
var range = [];
if (arr[0]>arr[1]){
for(var i =arr[1]; i<=arr[0];i++){
range.push(i);
}
}else{
for(var j = arr[0]; j<=arr[1]; j++){
range.push(j);
}
}
var counter =1;

for(var k = 0 ; k < range.length; k++){

if(counter% range[k] !== 0){
counter++;
k=0;
}

}
return counter;
}

// test here
smallestCommons([23,18]);``````
I fixed it a little but its still failing one of the test cases.
any ideas?
Joel Y.
@zapcannon99
Sep 17 2017 19:12
@FlashHero or rather codepen
FlashHero
@FlashHero
Sep 17 2017 19:14
@zapcannon99 codepen allows global variables
Joel Y.
@zapcannon99
Sep 17 2017 19:15
@FlashHero idk, I had to move that first line into the function for it to spit back something other than undefined
How do you make it global?
FlashHero
@FlashHero
Sep 17 2017 19:16
@zapcannon99 if its inside a function then that's a local variable, if its outside then its global variable
Joel Y.
@zapcannon99
Sep 17 2017 19:18

You know what, I just remembered that the challenges are done in fcc, not codepen, so my bad

But, codepen doesn't seem to allow global vars either. Again, I had to move that first line inside the function for it to work.

FlashHero
@FlashHero
Sep 17 2017 19:21
@zapcannon99 this works in codepen
``````var text='hello';
function action(){
console.log(text);
}
action();``````
Joel Y.
@zapcannon99
Sep 17 2017 19:33
Weird. doesn't work for the OP's code.
But yeah, point taken. I'll just have to be careful
monkeyfingerz
@monkeyfingerz
Sep 17 2017 19:37
``````function smallestCommons(arr) {
//noprotect
var range = [];
if (arr[0]>arr[1]){
for(var i =arr[1]; i<=arr[0];i++){
range.push(i);
}
}else{
for(var j = arr[0]; j<=arr[1]; j++){
range.push(j);
}
}
var counter =1;

for(var k = 0 ; k < range.length; k++){

if(counter% range[k] !== 0){
counter++;
k=0;
}

}
return counter;
}

// test here
smallestCommons([23,18]);``````
this answer according to the test should be 6056820.
Joel Y.
@zapcannon99
Sep 17 2017 19:42
@monkeyfingerz What answer do you get?
monkeyfingerz
@monkeyfingerz
Sep 17 2017 19:50
@zapcannon99
2018940
Joel Y.
@zapcannon99
Sep 17 2017 19:54
x3 will get you the answer it seems, hmmm
Joel Y.
@zapcannon99
Sep 17 2017 20:04
@monkeyfingerz
Oddly enough, if you go backwards on the for loop and make k = range.length every time it is non-zero, it works
You reasoning is sound, but I'm still trying to figure out why it seems to failing to continue counting
imperial-isms
@imperial-isms
Sep 17 2017 20:06
What am I missing that’s making this infinite?
``````var num = 9;

do {
switch (num) {
case (num % 2 === 1):
num = num % 2;
break;
case (num % 1 === 0):
num = num % 1;
break;
default:
break;
}
}

while (num !== 0);``````
Joel Y.
@zapcannon99
Sep 17 2017 20:07
Are you sure you can do conditionals like that for switch case?
Gersho
@Gersho
Sep 17 2017 20:08
i think you need the condition as the switch
Joel Y.
@zapcannon99
Sep 17 2017 20:08
All examples for switch case has something along the lines of if num is equal to an exact value
like
``````switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}``````
@Gersho That only works if there's only 1 condition, but he's got 2
imperial-isms
@imperial-isms
Sep 17 2017 20:09
Okay
Joel Y.
@zapcannon99
Sep 17 2017 20:10

I think you'd be better off with an if-else chain if you want to put multiple conditions like that

Then again, I'm a noob, so maybe somebody else knows the secret :/

imperial-isms
@imperial-isms
Sep 17 2017 20:11
I’m converting roman numerals, and I had considered if/else, but the switch seemed more legible
korzo
@korzo
Sep 17 2017 20:12

@zapcannon99 @Gersho

``````var num = 5;
switch(true) {
case (num===5):
console.log(5);
break;
case (num === 4):
console.log(4);
break;
default:
console.log('Default');
}``````

you can use expression in case and it's evaluated against argument of switch

imperial-isms
@imperial-isms
Sep 17 2017 20:12
Ah
Gersho
@Gersho
Sep 17 2017 20:14
that's cool to know but i think i would have a talk with the guy who made it if i had to maintain such thing
Joel Y.
@zapcannon99
Sep 17 2017 20:15
Ooh. There we go, the noob in me learned something.
korzo
@korzo
Sep 17 2017 20:15
It's useful , because it's more readable as series of if/else conditions
Joel Y.
@zapcannon99
Sep 17 2017 20:16

@monkeyfingerz

I dunno why it took me so long to figure it out.

The problem is that you're resetting k to 0. When it goes to back to the beginning of the for loop, it's adding 1 to k before iterating again. the check against 18 is never done.

imperial-isms
@imperial-isms
Sep 17 2017 20:24
Shouldn’t this work…
``````var i = 9;
for (i;i > 0;) {
if (i % 2 === 1) {
i = i % 2;
}
else if (i % 1 === 0) {
i = i % 1;
}
}``````
Joel Y.
@zapcannon99
Sep 17 2017 20:29
If you're going to do that, you might as well make a while loop
And also, `1 % 2 === 1`
imperial-isms
@imperial-isms
Sep 17 2017 20:32
AH!
That’s what was messing me up
Thanks!
Joel Y.
@zapcannon99
Sep 17 2017 20:36
np
Thayyeb salim
@Thayyebsalim
Sep 17 2017 20:57
thanks @korzo
CamperBot
@camperbot
Sep 17 2017 20:57
thayyebsalim sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
Ellyria
@Ellyria
Sep 17 2017 21:06
I'm playing around with while loops and for loops and translating between them by writing them in various ways. In the following example, I wrote a successful while loop, but when I translate it into a for loop it falls over and I'm not sure why. Anybody have an idea?
``````                <script>
console.log("USE A WHILE LOOP TO PRINT ALL NUMBERS BETWEEN 5 AND 50 THAT ARE DIVISIBLE BY 3 AND 5.");
num = 5;
while( num <= 50 ) {
if( num % 3 == 0 && num % 5 == 0 ) {
console.log(num);
}
num++;
}
</script>
<script>
console.log("USE A FOR LOOP TO PRINT ALL NUMBERS BETWEEN 5 AND 50 THAT ARE DIVISIBLE BY 3 AND 5.");
for(var i = 5; i <= 50; i++){
console.log(i);
if( i % 3 == 0 && i % 5 == 0 ) {
console.log(i);
}
}
</script>``````
Interesting. The syntax highlighting is showing that something is wrong, but I'm not getting an error in my console.
Gersho
@Gersho
Sep 17 2017 21:08
i tried to copy it in a fcc challenge page, it shows normal coloration
Ellyria
@Ellyria
Sep 17 2017 21:08
Do you see the messed up highlighting above, too, or is it just at my end?
It's treating my for loop as a string on my screen.
Gersho
@Gersho
Sep 17 2017 21:09
i see it, too much yellow, but when copied elsewhere it doesn't show up
Joel Y.
@zapcannon99
Sep 17 2017 21:09
the highlighting is not perfect
so don't trust it too much
Gersho
@Gersho
Sep 17 2017 21:09
i think it's because more than 80characters on the line
Ellyria
@Ellyria
Sep 17 2017 21:10
Yeah, and it's not tossing an error in the console, but as you can see if you run it, only the while loop works properly.
Joel Y.
@zapcannon99
Sep 17 2017 21:10
There's nothing wrong with the syntax so far as I can tell
Ellyria
@Ellyria
Sep 17 2017 21:10
Ah, okay.
Yeah, but it doesn't work.
Gersho
@Gersho
Sep 17 2017 21:10
yeah, can't see anything wrong too
have you tried with i= 5 instead of var i=5 ?
Ellyria
@Ellyria
Sep 17 2017 21:10
No, but I used var i = 5 on all of my examples and this is the only one that falls over.
Gersho
@Gersho
Sep 17 2017 21:11
why do you log i twice by the way ? (once outstide the if, once inside)
Joel Y.
@zapcannon99
Sep 17 2017 21:12
yeah I was going to say
it's logging twice
if you take out the first log outside the ifs you'll get the same output
Ellyria
@Ellyria
Sep 17 2017 21:13
That was an outright mistake. Whoops! Only one now.
monkeyfingerz
@monkeyfingerz
Sep 17 2017 21:13
@zapcannon99 Any idea how to adjust this piece of code to a working solution or do i need to rethink this
Ellyria
@Ellyria
Sep 17 2017 21:13
Heh, that fixed it. User error. Thanks! I wasn't seeing it for some reason.
Gersho
@Gersho
Sep 17 2017 21:13
\o/
Joel Y.
@zapcannon99
Sep 17 2017 21:14
@monkeyfingerz try k=-1 instead of k=0 every time it misses (hits that conditional you have)
Ellyria
@Ellyria
Sep 17 2017 21:14
Heh, I should have caught that. Boo on me. I've been looking at too many of these. I took an assignment I was doing and decided to find all the ways I could do it instead of one way and ended up with a whole bunch of ways of coding that.
Joel Y.
@zapcannon99
Sep 17 2017 21:15
Look at anything for too long and you're bound to miss simple things. Happens to the best of us.
Gersho
@Gersho
Sep 17 2017 21:15
@Ellyria you should go check codewars then, it has solution comparison
Ellyria
@Ellyria
Sep 17 2017 21:16
@Gersho, yeah, I'm afraid to do that. I suffer from major impostor syndrome and worry that my solutions might get laughed at, so I just don't participate.
monkeyfingerz
@monkeyfingerz
Sep 17 2017 21:16
Cool Thank you @zapcannon99
CamperBot
@camperbot
Sep 17 2017 21:16
monkeyfingerz sends brownie points to @zapcannon99 :sparkles: :thumbsup: :sparkles:
FlashHero
@FlashHero
Sep 17 2017 21:16
Any useful hints on advanced algorithm challenge called Exact change
Ellyria
@Ellyria
Sep 17 2017 21:16
All I can say is, "Good luck. We're all counting on you," @FlashHero. I'm not up to that yet.
Joel Y.
@zapcannon99
Sep 17 2017 21:17
@Ellyria
Don't forget Gersho
@FlashHero What kind of hint?
Gersho
@Gersho
Sep 17 2017 21:18
@FlashHero take the time to think carefully at each step, as if you were the one in front of the register
@Ellyria you could also discover that some people have solution even more ridiculous than yours
Ellyria
@Ellyria
Sep 17 2017 21:19
Heh, that's true!
FlashHero
@FlashHero
Sep 17 2017 21:20
@Gersho ok
monkeyfingerz
@monkeyfingerz
Sep 17 2017 21:22
@zapcannon99 that didn't work
i want my brownies back ;)
Gersho
@Gersho
Sep 17 2017 21:24
giving is giving, taking back is stealing :D
could you show your current code with an explaination of what you're trying to do and/or challenge url ?
Joel Y.
@zapcannon99
Sep 17 2017 21:28
``````function smallestCommons(arr) {
//noprotect
var range = [];
if (arr[0]>arr[1]){
for(var i =arr[1]; i<=arr[0];i++){
range.push(i);
}
}else{
for(var j = arr[0]; j<=arr[1]; j++){
range.push(j);
}
}
var counter =1;

for(var k = 0 ; k < range.length; k++){

if(counter% range[k] !== 0){
counter++;
k=0; //<--Change this line
}

}
return counter;
}

// test here
smallestCommons([23,18]);``````
Like I promise you were one step away with this code
Gersho
@Gersho
Sep 17 2017 21:30
lol range confused me, it looked like python
monkeyfingerz
@monkeyfingerz
Sep 17 2017 21:30
No that doesn't work
Joel Y.
@zapcannon99
Sep 17 2017 21:31
did you copy my code or did you change that line I pointed out?
I copied your code, made one change, and it passed all tests
monkeyfingerz
@monkeyfingerz
Sep 17 2017 21:32
Yeah it did n't pass either
Gersho
@Gersho
Sep 17 2017 21:32
i'd love to help but i don't really understand the maths going on with counter, did it a completely different way
monkeyfingerz
@monkeyfingerz
Sep 17 2017 21:32
are you on the challenge smallest common multiple
Joel Y.
@zapcannon99
Sep 17 2017 21:33

@Gersho

I was a little confused at first as well. Basically, he's counting up from 1 and checking against every number in the range that is specified in the arguments. As soon as 1 fails, increment counter and resets k.

Gersho
@Gersho
Sep 17 2017 21:35
i used the method called "prime factorisation" http://www.math.com/school/subject1/lessons/S1U3L3DP.html
because while i like to code, i hate maths
Joel Y.
@zapcannon99
Sep 17 2017 21:36
@Gersho
That's kinda funny, cuz @monkeyfingerz 's method is the brute force way that doesn't require smart math. Prime factorization is supposed to be the mathy way to do it.
monkeyfingerz
@monkeyfingerz
Sep 17 2017 21:36
yeah my solution is super slow
Joel Y.
@zapcannon99
Sep 17 2017 21:37
But it works
monkeyfingerz
@monkeyfingerz
Sep 17 2017 21:37
well not really
still can't pass the challenge
Joel Y.
@zapcannon99
Sep 17 2017 21:37
eh?
Gersho
@Gersho
Sep 17 2017 21:37
maybe, but i simply copied it from a math site ^^ the link provided in the challenges explains what lcm is, but not how to find is, if i hadn't googled that method, i would have never made that challenge, the math is beyond me
Joel Y.
@zapcannon99
Sep 17 2017 21:37
I don't know why it's not passing for you but your solution works.
For me.
Gersho
@Gersho
Sep 17 2017 21:37
try reseting the challenge and copying the stuff back in it
Joel Y.
@zapcannon99
Sep 17 2017 21:38
@Gersho fair enough
@monkeyfingerz yeah, maybe a reset may help. Like the screenshot is all I can show you to prove you are 2 chars away from happiness
Gersho
@Gersho
Sep 17 2017 21:39
that's one of my rare commented code, because i had to comment it to understand it xD
``````function smallestCommons(arr) {
var fullArr = [];
var primeFactors = [];
var factorsQt = {};
var tempFactors = {};
var result = 1;
if (arr[0]>arr[1]){
arr.reverse();
}

for (i=arr[0]; i<=arr[1]; i++){
fullArr.push(i);
}

for (i=0; i<fullArr.length;i++){   // prime factorize each entry
primeFactors.push([]);

for (j=2; j<=fullArr[i]; j++){
while ((fullArr[i] % j) === 0) {
primeFactors[i].push(j);
fullArr[i] /= j;
}

}
}

for (i=0; i<primeFactors.length;i++){    //count factor occurence in object
tempFactors = {};

for (j=0; j<primeFactors[i].length;j++){

tempFactors[primeFactors[i][j]] = (tempFactors[primeFactors[i][j]] || 0) + 1;

}

for (var value in tempFactors) {  //transfert temp data to actual object to keep only highest occurence

if (!factorsQt.hasOwnProperty(value)){
factorsQt[value] = tempFactors[value];
}

if (tempFactors[value] > factorsQt[value]){
factorsQt[value] = tempFactors[value];
}

}

}

for (var key in factorsQt)  {    // multiply the values
result *= Math.pow(key, factorsQt[key]);

}

return result;
}

smallestCommons([23,18]);``````
monkeyfingerz
@monkeyfingerz
Sep 17 2017 21:40
I diin't see that it was - oh vei thank you @Gersho @zapcannon99
CamperBot
@camperbot
Sep 17 2017 21:40
monkeyfingerz sends brownie points to @gersho and @zapcannon99 :sparkles: :thumbsup: :sparkles:
api offline
Joel Y.
@zapcannon99
Sep 17 2017 21:40
oh, you mean the -1?
k=-1?
monkeyfingerz
@monkeyfingerz
Sep 17 2017 21:41
yeah lol
really frustrating when something so simple can through everything off
Joel Y.
@zapcannon99
Sep 17 2017 21:42
I know exactly how you feel
Lucci Paula
@luccipaula
Sep 17 2017 22:13
Hey guys, I think I'm nearly done with my Wikipedia viewer but I was wondering how I should go about displaying an AJAX error message if something goes wrong... Still very new to AJAX calls 😅 https://codepen.io/vivalucci/full/KvBBQp/
Any other feedback on the project would be appreciated as well! :)
Gersho
@Gersho
Sep 17 2017 22:16
well you already have your fail setup, you only need to put something in it
like \$(".articles").append("something went wrong, i'm really sorry, please try again later");
you could grab the err message you got from ajax, but the user doesn't really care anyway
Lucci Paula
@luccipaula
Sep 17 2017 22:18
@Gersho Yeah but what is the difference between fail and error? I've seen some use error. Also not sure how to test it to get it to fail because when I type random characters it doesn't trigger.
You're right about that, I was just curious and trying to get used to error handling :P
Gersho
@Gersho
Sep 17 2017 22:18
i usually use error, i assumed fail would work since you've already put it in your code, but i don't know about it
when you type random chars, your ajax doesn't fail or errors in any way, it does its work, asking wikipedia for osdflaookubs , and wikipedia will answer that it didn't find anything, but there was no error here
Lucci Paula
@luccipaula
Sep 17 2017 22:20
I see, so it just won't return anything
So maybe I can put in the success function that if the results length is equal to zero, show an "error" message?
Gersho
@Gersho
Sep 17 2017 22:21
well if you call someone to ask for some information, if that person doesn't have the info you want doesn't mean your phone is broken
Lucci Paula
@luccipaula
Sep 17 2017 22:22
Good point
Gersho
@Gersho
Sep 17 2017 22:23
if that's what you're trying to catch (random stuff having no result) you could put a check for the length, but in the success (since it's a success) with something like "nothing found" or "hsfjshdfkjh yielded no results" (so the user know it's not an error)
Lucci Paula
@luccipaula
Sep 17 2017 22:24
Right, that's what I was thinking of. @Gersho Thanks
CamperBot
@camperbot
Sep 17 2017 22:24
caixeta-paula sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
Gersho
@Gersho
Sep 17 2017 22:25
you have a good point in the logic of it, just checked on mine, if you put randomstuff it doesn't do anything and the user can't know if it's working or not
Lucci Paula
@luccipaula
Sep 17 2017 22:27
Thanks haha, lately I've been trying to think about making my projects a bit more user-friendly
Lucci Paula
@luccipaula
Sep 17 2017 22:34
Fixed it nicely I think
Gersho
@Gersho
Sep 17 2017 22:35
...
when i type mdklf
i didn't expect it to find something >.>
Lucci Paula
@luccipaula
Sep 17 2017 22:36
Haha yeah I typed in "poopface" and it gave me a Swedish band named "Popface"
Gersho
@Gersho
Sep 17 2017 22:36
and yeah your message is cool
Lucci Paula
@luccipaula
Sep 17 2017 22:36
Thank you 😁