// [1] 기본 콘솔 출력 방법, 자료구조, 기본 연산 문법 (Intorduction to JavaScript)
console.log(5)
console.log(50)
// Opening line.
console.log('It was love at first sight.');
/*
console.log('The first time Yossarian saw the chaplain he fell madly in love with him.');
console.log('Yossarian was in the hospital with a pain in his liver that fell just short of being jaundice.');
console.log('The doctors were puzzled by the fact that it wasn\'t quite jaundice.');
console.log('If it became jaundice they could treat it.');
console.log('If it didn\'t become jaundice and went away they could discharge him.');
console.log('But this just being short of jaundice all the time confused them.');
*/
console.log('JavaScript')
console.log(2011)
console.log('Woohoo! I love to code! #codecademy')
console.log(20.49)
console.log(1+3.5)
console.log(2026-1969)
console.log(65/240)
console.log(0.2708* 100)
console.log('Hello'+'World')
console.log('Hello '+'World')
console.log('Teaching the world how to code'.length)
// Use .toUpperCase() to log 'Codecademy' in all uppercase letters
console.log('Codecademy'.toUpperCase());
// Use a string method to log the following string without whitespace at the beginning and end of it.
console.log(' Remove whitespace '.trim());
console.log(
Math.floor(Math.random()*100)
)
console.log(
Math.ceil(43.8)
)
console.log(
Number.isInteger(2017)
)
// [2] 변수 선언, 유형, 조작
var favoriteFood = 'pizza'
var numOfSlices = 8
console.log(
favoriteFood, numOfSlices
)
let changeMe = true
console.log(changeMe)
changeMe = false
console.log(changeMe)
const entree = 'Enchiladas'
console.log(
entree
)
entree = 'Tacos'
let levelUp = 10;
let powerLevel = 9001;
let multiplyMe = 32;
let quarterMe = 1152;
// Use the mathematical assignments in the space below:
levelUp += 5
powerLevel -= 100
multiplyMe *= 11
quarterMe /= 4
// These console.log() statements below will help you check the values of the variables.
// You do not need to edit these statements.
console.log('The value of levelUp:', levelUp);
console.log('The value of powerLevel:', powerLevel);
console.log('The value of multiplyMe:', multiplyMe);
console.log('The value of quarterMe:', quarterMe);
let gainedDollar = 3;
let lostDollar = 50;
gainedDollar++;
lostDollar --;
let favoriteAnimal = 'dog';
console.log(
'My favorite animal: ' + favoriteAnimal
);
const myName = 'ssw';
const myCity = 'Texas';
console.log(
`My name is ${myName}. My favorite city is ${myCity}.`
)
let newVariable = 'Playing around with typeof.';
console.log(
typeof newVariable
)
newVariable = 1
console.log(
typeof newVariable
)
// free mini pratice1: Kelvin Weather
// kelvin temperature
const kelvin = 0;
// transforming kelvin into celsius
let celsius = kelvin - 273;
// fqhrenheit
let fahrenheit = celsius * (9/5) + 32;
// round value
fahrenheit = Math.floor(fahrenheit);
console.log(
`The temperature is ${fahrenheit} degrees Fahrenheit.`
);
let Newton = celsius * 33/100
console.log(
`The temperature is ${Newton} degrees Newton.`
);
// free mini practice2: Dog Years
// myage
const myname = 'ssw'
let myAge = 33;
//
let earlyYears = 2;
earlyYears *= 10.5;
//
let laterYears = myAge - 2;
laterYears *= 4;
console.log(
earlyYears, laterYears
);
let myAgeInDogYears = earlyYears + laterYears
console.log(
`My name is ${myname}. I am ${myAge} years old in human years, which is ${myAgeInDogYears} old in dog years.`
);
// [3] 조건문, 불리언 개념, 스위치
let sale = true;
sale = false;
if (sale) {
console.log('Time to buy!');
} else {
console.log('Time to wait for a sale.');
}
let hungerLevel = 7
if (hungerLevel > 7 ) {
console.log('Time to eat!')
} else {
console.log('We can eat later!')
}
let mood = 'sleepy';
let tirednessLevel = 6;
if (mood === 'sleepy' && tirednessLevel > 8) {
console.log('time to sleep');
} else {
console.log('not bedtime yet');
}
let wordCount = 1;
if (wordCount) {
console.log("Great! You've started your work!");
} else {
console.log('Better get to work!');
}
// let favoritePhrase = '';
// if (favoritePhrase) {
// console.log("This string doesn't seem to be empty.");
// } else {
// console.log('This string is definitely empty.');
// }
let tool = 'marker';
// Use short-circuit evaluation to assign writingUtensil variable below:
let writingUtensil = tool || 'pen'
console.log(`The ${writingUtensil} is mightier than the sword.`);
let isLocked = false;
isLocked? console.log('You will need a key to open the door.')
: console.log('You will not need a key to open the door.');
let isCorrect = true;
isCorrect? console.log('Correct!')
:console.log('Incorrect!');
let favoritePhrase = 'Love That!';
favoritePhrase === 'Love That!'? console.log('I love that!')
:console.log("I don't love that!");
let season = 'summer';
if (season === 'spring') {
console.log('It\'s spring! The trees are budding!');
} else if (season === 'winter') {
console.log('It\'s winter! Everything is covered in snow.');
} else if (season === 'fall') {
console.log('It\'s fall! Leaves are falling!');
} else if (season === 'summer') {
console.log('It\'s sunny and warm because it\'s summer!');
} else {
console.log('Invalid season.');
}
let athleteFinalPosition = 'first place';
switch (athleteFinalPosition) {
case 'first place':
console.log('You get the gold medal!');
break;
case 'second place':
console.log('You get the silver medal!');
break;
case 'third place':
console.log('You get the bronze medal!');
break;
default:
console.log('No medal awarded.');
break;
}728x90
반응형
'Programming > JavaScript' 카테고리의 다른 글
| [CodeAcademy] Array, loop, Iterators (0) | 2026.04.08 |
|---|---|
| [CodeAcademy] 함수 (0) | 2026.04.08 |
| Tap(for) (0) | 2023.11.07 |
| Scroll (0) | 2023.11.07 |
| Regular Expression(정규식), 캐러셀, toFixed, parseFloat (0) | 2023.11.07 |