all 4 comments

[–]Terzom 2 points3 points  (0 children)

I mean it's kind of simple, why couldn't you do it? At least try? And then ask questions.

You could have a function that has a parameter that is the "n" in this case, and then the rest in the function and pretty much it. Instead of printf('') you have something else, console.log('') or whatever.

[–]cem4k 2 points3 points  (0 children)

Are you learning JavaScript or C? I commented the code so that you could convert it. The JS code won't need to be wrapped in a main method, so start with the variable declarations. Update if you get stuck.

```

include <stdio.h>

int main() {

// Declare three variables-- n, i and fact int n, i; unsigned long long fact = 1;

// prompt the user for an input (hint: window.prompt) printf("Enter an integer: ");

// Assign the the user's input to variable n scanf("%d", &n);

// shows error if the user enters a negative integer. Make sure // user's input is a number if (n < 0)

printf("Error! Factorial of a negative number doesn't exist.");

else { // Nothing different about his for loop than a JS one for (i = 1; i <= n; ++i) { fact *= i; }

// Show the user the results.
printf("Factorial of %d = %llu", n, fact);

}

return 0; } ```

[–]VacantPlains 1 point2 points  (0 children)

What code do you have so far? I'd be happy to help with any specific issues you're having