Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript FCC 25 + 5 clock project

lorelei

Coder
Hi all.
I'm wondering if someone here would be willing to take a look at my code?
It needs to pass the 25+5 clock test (visible in the left corner drop down menu )
I've tried everything to make all tests pass, but it seems near hopeless. I know some test is not the be all end all, but I just want to know where I'm going wrong.
I'll just post a codepen link:

codepen


Thanks :)
 
To start, I think the "simplest" way to check is to confirm that you're fulfilling the user stories mentioned in the challenge. In saying that, the challenge mentions 28 user stories but there are 29 tests. Unfortunately it looks like there's a mismatch.

It looks like it's possible to add the tests to an environment outside of CodePen (but I haven't tried). If you look at the HTML section of the pen you can see <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script> - this contains the test suite. I was trying to look for the source code for the tests in their GitHub area but couldn't find anything. Maybe it's not something they make publically available to prevent cheating.

I've managed to get a better look at the code in that bundle.js - you can run it through this site https://unminify.com/ to get better formatting. You can do a search for "25-5-clock" and this will show you the code for the tests. What seems good: there's descriptions of each of the tests, the bad: it doesn't seem to show you which ones fail. Maybe you could add something like console.log for failed tests?
 
Thanks for the reply and trying. If you run the code in the codepen , bottom left just press the three stripes , and search for the 25+5 clock test.


I've been trying a different approach, but it doesn't seem easy right of the bat.

with this code I separated the break from the app, can do the same for session.

But I know that the break value is needed later when the switch happens from session to a break and back.
But the updated break value (count) is not accessible from within App , so how do I solve that?

JavaScript:
const Break = (props)=>{
   const [count,setcount] = React.useState(props.breaks);
   return (
      <div>
         <button onClick={()=>setcount(count-1)}>-</button>
         {count}
         <button onClick={()=>setcount(count+1)}>+</button>
      </div>
 
   );
}
class App extends React.Component {
  constructor(props){
    super(props);
    this.state={
      break: 5,
      session: 25,
     
    }
  }
  render(){
     return(
        <Break breaks={this.state.break}/>
     );
  }
}
ReactDOM.render(<App/>,document.getElementById('container'));
 
could someone please give some insight with my direct above this post code snippit ?

And, is it normal to be this stuck with react again. I feel like I'm getting nowhere, I keep having to redo beginner js/react tutorials. Maybe I'm not cut out for this.
 
Never mind, I figured out the code snippet. Using nested components, honestly I feel i'm back at square one .
Still stuck with the 25+5 code, but I'll see how this new code will work out.
 
Sorry, I can't really provide you any feedback regarding your code. ReactJS and associated framework is on my TODO list.

Maybe I'm not cut out for this.

Coding and programming is one of those things that take time and practice. Please don't give up. We've all been in that situation where there's a problem that's stumped us, but you can get the result you want in the end. Keep it up! You can do this!
 
Never mind, I figured out the code snippet. Using nested components, honestly I feel i'm back at square one .
Still stuck with the 25+5 code, but I'll see how this new code will work out.
As @Krusty the Senile mentioned, don't just quit! Keep practicing, you figured out the code snippet. That's more than enough to tell you to keep going! Code Forum will always be behind you. So don't ever quit!
 
Thanks Malcolm, never saw your reply sorry :)

I managed to get it to work for 2 different versions, one is just plain JS, the other uses a react class. They work and pass the FCC test!

But I have another version using React components and a class, that I can't get to work.
Well , it seems to work correctly when I run it by pressing the buttons.
But the freecodecamp test doesnt pass it. This is for the 25+5 timer.
Hopefully I'll be able to finish it soon , otherwise I'll be here again for help .
 
Last edited:

Buy us a coffee!

Back
Top Bottom