24T3 Week 1
Wednesday 5PM - 7PM (W17A)
Slides by Alvin Cherk (z5311001)
Getting help (https://cgi.cse.unsw.edu.au/~cs1531/)
git add
git commit
git push
git status
git log
When you commit
something, you are effectively saving the staged files as a new snapshot and signing it with your name and email.
You have to configure your git identity if you haven't done it before.
git config --global user.name "Your Name Here"
git config --global user.email "z555555@unsw.edu.au"
You then can add whatever email you have set in user.email on GitLab, so that it recognises all the commits that have been pushed to GitLab.
Please do this, its important Git etiquette.
It also allows your tutor to track the work you have done in your pair assignment.
#include <stdio.h>
#define SIZE 10
void print_parity(int num);
int main(void) {
char message[] = "Welcome to COMP1531!";
printf("%s\n", message);
printf("Numbers from 1 to %d\n", SIZE);
for (int num = 1; num <= SIZE; num++) {
print_parity(num);
}
return 0;
}
void print_parity(int num) {
if (num % 2 == 0) {
printf("EVEN: %d\n", num);
} else {
printf("ODD: %d\n", num);
}
}
const
and let
?console.log
function different to printf
in C?2=='2'
return? why?main
function?// No #include
// no main function
const SIZE = 10; // Dynamically typed & const
const message = 'Welcome to COMP1531!'; // Single quotes
console.log(message); // No '\n'
console.log(`Numbers from 1 to ${SIZE}`); // Recommended string layout
for (let num = 1; num <= SIZE; num++) { // let
print_parity(num);
}
function print_parity(num) { // function & no type in parameter & no return type
if (num % 2 === 0) { // Triple equals
console.log(`EVEN: ${num}`);
} else {
console.log(`ODD: ${num}`);
}
}
Javascript objects are just a collection of properties, kinda like structs, but better. Properties are key value pairs in the form key: value
where keys are strings or numbers and values can be of any type (String, Number, Array, Object, etc..).
let fruit = {
name: 'apple',
cost: 2
}
const arr = [1, 2.02, "3"]
for (const of in arr) {
console.log(typeof(i))
}
How can we get the name and cost of the fruit in the object above?
Brainstorm ways we can loop through the shopping list given in loopy.js to print the names of all items in the shopping list?
Why should we use for of loops instead of for in loops where possible?
(typeof
is a function that returns a string with the type of the argument passed in. what does this program output?)
While we haven't given you a style guide yet, it's still important to maintain good style! Most styling rules taught in 1511 still apply.
Take a look at style.js. It contains many style issues :< You will have 5 minutes to review the code in your groups and identify as many style issues as you can!
JavaScript is a high-level language with many built-in features that simplify common tasks. This built-in functionality makes it easier to read, write and debug code :3
Today, we’ll focus on array methods. These are like functions specifically designed for performing common operations on arrays, such as adding elements, finding items, sorting, and more. We’ve already used the length
method earlier to determine the number of elements in an array!