This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const arr = [1, 2, 3, 4, 5, 6]; | |
| let rt = 0; | |
| for (let i = 0; i <= arr.length; i++) { | |
| rt += i; | |
| } | |
| console.log(rt) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var twoSum = function(nums, target) { | |
| for (let i = 0; i < nums.length; i++){ | |
| for (let j = 0; j < nums.length; j++){ | |
| if(nums[i] + nums[j] == target && i !=j) { | |
| return [nums[i], nums[j]]; | |
| } | |
| } | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1 | |
| let n = 3; | |
| if (n % 2 === 0) console.log("even"); | |
| else console.log("odd"); | |
| // 2 | |
| let age = 7; | |
| let minAge = 7; | |
| let maxAge = 12; | |
| if (age >= minAge && age <= maxAge) console.log(true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 1 | |
| var fizzBuzz = function(n) { | |
| let output = []; | |
| for (let i = 1; i <= n; i++) { | |
| let temp = ""; | |
| if (i % 3 == 0 && i % 5 == 0) temp += 'FizzBuzz'; | |
| else if (i % 3 == 0) temp += 'Fizz'; | |
| else if (i % 5 == 0) temp += 'Buzz'; | |
| else temp += i; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let firstName = "Nguyen"; | |
| let lastName = "Nhan"; | |
| let age = "24"; | |
| let job = "software engineering"; | |
| let salary = "100"; | |
| console.log(`My name is ${firstName} ${lastName}, i'm ${age} years old. I work as ${company} and make ${salary}`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const players = [ | |
| {jersey:56,name:"Djounte Murray",position:"Point guard",PPG:2.6}, | |
| {jersey:98,name:"Dennis Rodman",position:"Small Forward",PPG:10.8}, | |
| {jersey:1,name:"Michael Jordan",position:"Small Forward",PPG:345.6}, | |
| {jersey:2,name:"Lebron James",position:"Shooting Guard",PPG:26.7}, | |
| {jersey:33,name:"Patrick Ewing",position:"Center",PPG:20.2} | |
| ] | |
| const player2 = players.map((key, value) => { | |
| if (key === PPG) return Math.floor(value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const cars = [ | |
| {name:'Ford',price:200}, | |
| {name:'Nissan',price:400}, | |
| {name:'Nissan',price:600} | |
| ] | |
| const str = cars.forEach((value)=> { | |
| console.log(`${value.name} is ${value.price}`); | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const channels = [ | |
| {name:'HBO',premium:true}, | |
| {name:'LIFE',premium:false}, | |
| {name:'Max',premium:true}, | |
| {name:'Cooking channel',premium:false}, | |
| {name:'WOBI',premium:false} | |
| ]; | |
| const preChannel = channels.filter(p => p.premium == true); | |
| console.log(preChannel) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const trips = [ | |
| {to:'Brazil',distance:1000}, | |
| {to:'Chine',distance: 2500}, | |
| {to:'India',distance: 3000} | |
| ] | |
| const initialValue = 0; | |
| const sumWithInitial = trips.reduce( | |
| (previousValue, currentValue) => previousValue += currentValue.distance, | |
| initialValue | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function kiemTra(mon1, mon2, mon3, khuVuc, doiTuong, diemChuan){ | |
| let totalDiem = mon1 + mon2 + mon3; | |
| if(khuVuc === "A") totalDiem += 2 | |
| if(khuVuc === "B") totalDiem += 1 | |
| if(khuVuc === "C") totalDiem += 0.5 | |
| if(doiTuong === 1) totalDiem += 2.5 | |
| if(doiTuong === 2) totalDiem += 1.5 | |
| if(doiTuong === 3) totalDiem += 1 | |
| if ( mon1 !== 0 && mon2 !== 0 && mon3 !== 0 && totalDiem >= diemChuan) | |
| console.log(`thi sinh duoc tong ${totalDiem} va dau`) |
OlderNewer