-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JavaScript code samples #13
Comments
Hi Jake, sorry for taking so long to respond. We would be very happy if you wanted to submit some JavaScript samples. Currently, we have a Wiki on our coding standards but we would need to add one for JavaScript. However, it should still give you an indication of the general approaches we take: https://github.com/raspberrypilearning/ada-code-samples/wiki |
I'll try to start some time soon with writing a coding standards page with a couple of code samples, so that we can agree on a coding standard for JS first. |
Thanks Jake, much appreciated! |
Attached is an example Things are a bit complicated with JavaScript when it comes to having a Below (which is also in the attached markdown) is an example program that has a function which is exported: // Add two numbers
function add (a, b) {
let sum = a + b
return sum
}
// The main method is the entry point when executed directly
function main () {
let sum = add(5, 7)
console.log(`The result of the addition was ${sum}`)
}
// This code will run if this file is executed directly
// (i.e. not called by another program)
if (import.meta.main) {
main()
}
// Export the function for use in other programs
export default add And an example which doesn't have an export, for a simple program: let sum = 0
for (let i = 0; i < 5; i++) {
sum += i
}
console.log(`The sum is ${sum}`) Any thoughts on my suggestions for how to handle let sum = add(5, 7)
console.log(`The result of the addition was ${sum}`)
// Add two numbers
function add (a, b) {
let sum = a + b
return sum
} |
I'm here atm with @dianedowling at your offices (I'm from Cambridge Maths School). If I submit some JavaScript code samples, can they be included on the website? Please let me know any details to follow re formatting etc for pull requests to be accepted.
The text was updated successfully, but these errors were encountered: