These are chat archives for FreeCodeCamp/HelpJavaScript

17th
Mar 2018
Stephen James
@sjames1958gm
Mar 17 2018 00:13
@AmitP88 You subtract 1 from seconds and then put it in the DOM without checking for underflow.
I really would be easier if you did all the math in seconds and then just convert to minutes/seconds on output.
function updateDisplay(time) {
   let minutes = Math.floor(time / 60);
   minutes_div.innerHTML = minutes < 10 ? '0' + minutes : minutes;
   let seconds = time % 60;
   seconds_div.innerHTML = seconds < 10 ? '0' + seconds : seconds;
 }
aRtoo
@artoodeeto
Mar 17 2018 00:14

hello guys. if anyone could help me. how can i handle undefined img? so i have this code.

iconDisplay(img){
            console.log(!img)
            if(!img){
                console.log( {backgroundImage: `url(${this.state.icon})`})
                return {backgroundImage: `url(${this.state.icon})`}
            } else {
                console.log({backgroundImage: `url(${this.state.icon})`})
                return {backgroundImage: `url(${this.state.icon})`}
            }
        }

and this is where it will be invoke

 <figure className="icon" 
              style={
              this.iconDisplay(this.state.icon)
             }
            alt={this.state.description}>
</figure>

this is the pen https://codepen.io/artoo/pen/BrjYrp?editors=0010

Stephen James
@sjames1958gm
Mar 17 2018 00:16
@artoodeeto Well you are not using img in that function, but what do you want to have happen if img == undefined?
Amit Patel
@AmitP88
Mar 17 2018 00:17
@sjames1958gm hmmm, I dunno, I thought I was taking a simpler approach, but maybe you're right. I'll see if I can do it that way
aRtoo
@artoodeeto
Mar 17 2018 00:18
@sjames1958gm i just want it to be nothing. it working. but when a different location because its not accurate it will pass to false and still return the else statement
Stephen James
@sjames1958gm
Mar 17 2018 00:18
@AmitP88 Seperate your calculations (time in seconds) from your display (time in minutes/seconds)
So you only have to worry about seconds == 0 being the end of the timer as a whole
aRtoo
@artoodeeto
Mar 17 2018 00:19
@sjames1958gm been observing it. if the location is in JAPAN then the img will be false so it will return the this.state.icon
Stephen James
@sjames1958gm
Mar 17 2018 00:19
@artoodeeto Your if and else are the same code?
Amit Patel
@AmitP88
Mar 17 2018 00:21
@sjames1958gm yeah, I tried to just have it in the global scope so that it could always apply, but whenever run() and reset_timer() are activated, it doesn't apply for some reason
Stephen James
@sjames1958gm
Mar 17 2018 00:25
@AmitP88 So all reset_timer has to do is the following (you don;t have to think about the display anymore once you have updateDisplay working
seconds = START_TIME;
// stop the timer
updateDisplay(seconds);
If you have a const START_TIME = 60; then you can update that variable once to set the clock to a longer value;
Amit Patel
@AmitP88
Mar 17 2018 00:26
@sjames1958gm do you think I should completely redo my js for this project?
like just scrap it and start over?
aRtoo
@artoodeeto
Mar 17 2018 00:27
@sjames1958gm no but for some reason theres a truthy value on the image that even if it returns no icon it will return this
main-js.js:106 {backgroundImage: "url(undefined)"}
Stephen James
@sjames1958gm
Mar 17 2018 00:27
@AmitP88 Just some refactoring, create a function that takes time in seconds and updates the display.
then in your run and reset_only manipulate time in seconds
@artoodeeto Well, since if img is undefined you still use the value of undefined, not sure what you expect?
aRtoo
@artoodeeto
Mar 17 2018 00:28
@sjames1958gm and i dont know why i get the location of japan.
Amit Patel
@AmitP88
Mar 17 2018 00:29
@sjames1958gm I see. but I'm also thinking about the increment/decrement buttons. I'd imagine that would have to involve some manipulating in seconds too
aRtoo
@artoodeeto
Mar 17 2018 00:29
@sjames1958gm if its undefined and i want it to be nothing but im just bothered by the error
Stephen James
@sjames1958gm
Mar 17 2018 00:29
@artoodeeto You function should be using img not this.state.icon and
if img is undefined then return { backgroundImage: "none"}
aRtoo
@artoodeeto
Mar 17 2018 00:30
@sjames1958gm ohhh fuck right. i was lost
Stephen James
@sjames1958gm
Mar 17 2018 00:30
@artoodeeto :0
aRtoo
@artoodeeto
Mar 17 2018 00:30
@sjames1958gm hold on sir let me try. hahaha. so freakin stupid. been doing this since morning. haha
Stephen James
@sjames1958gm
Mar 17 2018 00:31
@AmitP88 So, if you have time in seconds, increment/decrement should be fairly easy.
Once you get the display code isolated to a function you can put that out of your mind
Stephen James
@sjames1958gm
Mar 17 2018 00:48
@artoodeeto Did that work?
@AmitP88 Did we lose you :)
Amit Patel
@AmitP88
Mar 17 2018 00:51
@sjames1958gm oh sorry, I was taking a break :)
tbh, I really don't want to scrap what I have, but I dunno, I'll try it your way
aRtoo
@artoodeeto
Mar 17 2018 01:06

@sjames1958gm no sir but i have other solution. the error is when the location is in JP there will be no icon but the condition will be pass as true. so what i did is this.

 iconDisplay(country){
            console.log(country !== 'US')
            if(country !== 'US'){
                // console.log(`dos`, {backgroundImage: `none`})
                return {backgroundImage: 'none'}
            } else {
                // console.log(`tres`,{backgroundImage: `url(${img})`})
                return {backgroundImage: `url(${this.state.icon})`}
            }
        }

if its not US then no background if its US get the background. it worked no errors now but im not satisfied.

@sjames1958gm i also set the 3rd call back to a highAccuracy its rarely now to gets the JP location like 10 press but i will still get it.
aRtoo
@artoodeeto
Mar 17 2018 01:11
@sjames1958gm thank you sir. :)
CamperBot
@camperbot
Mar 17 2018 01:11
artoodeeto sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9103 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
TuTopMóvil
@TuTopMovil_twitter
Mar 17 2018 10:19
Buenas, soy nuevo y me gustaria contar con una persona que me ayude a iniciar en este mundo de programacion..
Matej Bošnjak
@mbosnjak01
Mar 17 2018 10:23
@TuTopMovil_twitter We speak English here :)
TuTopMóvil
@TuTopMovil_twitter
Mar 17 2018 10:23
oohhh!!! Sorry...
Razvan Jackson
@RazvanJackson
Mar 17 2018 12:45
Hey, can someone help me with react and express twitter-passport?
Sadio Ali
@5adiyah
Mar 17 2018 23:55
Anyone here familiar with Ember.js and Wordpress API? Trying to connect the two following this tutorial https://www.codesandnotes.com/ember-js/ember-wordpress/ but I'm getting this error: Error while processing route: members Assertion Failed: You must include an 'id' for member in an object passed to 'push' .... any ideas how to fix it? Here's a full detailed post on my question https://stackoverflow.com/questions/49342824/error-assertion-failed-you-must-include-an-id-for-member-in-an-object-passed