Build with Code using Codesmith's Self-paced Learning Resources
Codesmith offers a variety of opportunities for learners at different stages of their coding...
INTRO TO FUNCTIONALITY
VARIABLES
let num = 6;
let name = ‘jane’;
const storeOfInfo = {
name: ‘sebastien’,
home: [‘france’, ‘nyc’],
};
const randomList = [1,‘2’, [3], {4: undefined}];
let introToJavaScriptIsAwesome = true;
CONTROL FLOW
const myGrade = 75;
if (myGrade <= 70) {
console.log(myGrade + ‘is failing.’);
} else if(myGrade < 80) {
console.log(myGrade + ‘is passing.’);
} else {
console.log(myGrade + ‘is excellent.’);
}
if (myGrade === 100) {
console.log(‘a perfect grade!’);
}
// what if we re-assign myGrade to 100?
LOOPING
const myGrades = [50, 75, 90];
let sum = 0;
for (let i = 0; i < myGrades.length; i++) {
// what is sum?
// what is i?
sum = sum + myGrades[i];
// now what is sum?
}
// what happens first and why?
let average = sum / myGrades.length;
NESTED LOOPING
const myNums = [50, 75, 90];
for (let i = 0; i < myNums.length; i++) {
const num1 = myNums[i];
// what is num1, i and myNums[i]?
for (let j = 0; j < myNums.length; j++) {
const num2 = myNums[j];
// what is num2, j and myNums[j]?
console.log(‘Sum: ’, num1 + num2);
}
};
COMBINING FUNCTIONALITY
const myNums = [1, 2, 3, 4, 5];
for (let i = 0; i < myNums.length; i++) {
const num1 = myNums[i];
for (let j = 0; j < myNums.length; j++) {
const num2 = myNums[j];
if (num1 + num2 === 7) {
console.log(‘Lucky Seven!’);
}
}
}
CONCLUSION
Codesmith offers a variety of opportunities for learners at different stages of their coding...
We’re excited to share the launch of JavaScript for Beginners on Udemy! This course is for anyone...