What is this site?
This is site was written by Grant Sander, and is an extension of cosmalearning.com. It was developed to support learners in exploring both math and programming. The site consists of various tutorials, examples, and exercises, ranging from basic programming concepts to some sophisticated mathematical ideas. Througout the site you will see code snippets that look like this:
print("I'm an editor!"); print("You can edit me, and run the code.");
Click on the code snippet to pull open the code in the editor on the right-side of the screen. You can edit the code in the code-editor, and then press the "Run" button to run your code. The output of your code will be shown below the code editor. You can also press Ctrl + Enter (or Cmd + Enter on Mac) to run your code.
You will see the
print() command very often throughout the site. The
print() command will print an output to the output section of the editor. As an example, if you want to know what 4 + 6.5 is, you could run
print(4 + 6.5);.
What is Coding/Programming?
Coding, or programming, is the process of writing computer programs. Computer programs are basically just commands telling a computer what to do. Let's look at a simple example of a program.
print("I'm a program!");
In the code editor above, there is a single line:
print("I'm a program!");. This line of code is just telling the computer, "print the statement 'I'm a program!' to the output". We are just telling the computer what to do in a language that it can understand. When looking at a program, the computer will generally work its way down the program, executing one line at a time. For example, consider the following program:
print("Hello, world!"); print("It's a great day to be alive!"); print("It's a great day to learn about coding!");
In the above program, there are now three lines of code. The computer just works its way down those three lines of code, executing each line of code when it gets to it. Try editing some of those lines, or adding your own! See how it changes the output to the right.
Adding Comments to Code
// notation. So,
// THIS IS A COMMENT will be interpreted as a comment, and the computer will not do anything with it. It's just so that we can add comments to our code so we can remember what we did. You will see these comments regularly throughout the code in this site.
print(3 + 5); print(10/2); print(5 + (3*2)); print(6/(2+1));
3(5). You will need to enter
To make this site more fun, mathematically, I have added a handful of extra math capabilities. For example, I have added some useful mathematical functions and constants - including the constant \(e\) and \(\pi\), as well as trigonometric and logarithmic functions. The editor below shows some of these math functions. It's okay if you don't know what all of them are, just be aware that you have some additional math functions available.
// Constants print( e ); print( pi ); // Trig functions print( sin(0.5) ); print( cos(0.5) ); print( tan(0.5) ); print( arcsin(0.5) ); // 3^2 is written as pow(3, 2) print( pow(3, 2) ); // log_4(16) written as log(16, 4) print( log(16, 4) ); // Natural log print( ln(e) );
The table below is a list of the additional math functions and what they do.
|The constant \(e\)|
|The constant \(\pi\)|
|Base to a power|
|The square root function|
|The sine function|
|The cosine function|
|The tangent function|
|The inverse sine function|
|The inverse cosine function|
|The inverse tangent function|
|The exponential function (base e)|
|The log function, base b|
|The natural log function|
|The greatest common denominator of a and b|
|The least common multiple of a and b|
|The ceiling function|
|The floor function|