Last active
February 25, 2024 04:12
-
-
Save syafiqfaiz/3dc5f6bcefecb7b2997d0a4e57e5866b to your computer and use it in GitHub Desktop.
latihan tambahan
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 markah = [80, 99, 57, 40, 88, 39] | |
// kirakan purata | |
// // pseudocode | |
// // tambah semua, bahagi dengan bilangan | |
// let hasilTambahSemua = 0 | |
// markah.forEach((nombor) => { | |
// hasilTambahSemua = hasilTambahSemua + nombor | |
// console.log(hasilTambahSemua) | |
// }) | |
// console.log('total', hasilTambahSemua) | |
// console.log('bilangan', markah.length) | |
// console.log('purata', hasilTambahSemua/markah.length) | |
// dapatkan markah tertinggi | |
// sort dulu | |
// return value last | |
// console.log('susuan asal', markah) | |
// markah.sort((a,b) => b-a) | |
// console.log('sorted', markah) | |
// console.log('markah tertinggi', markah[markah.length-1]) | |
// dapatkan gred | |
// A = 80 --> 100 | |
// B = 70 --> 79 | |
// C = 40 --> 69 | |
// F = less than 40 | |
// generate new array with grade | |
// console.log('markah asal', markah) | |
// const grade = markah.map((nombor) => { | |
// if (nombor >= 80 ){ | |
// return 'A' | |
// } else if (nombor >= 70 && nombor <= 79 ){ | |
// return 'B' | |
// } else if (nombor >= 40 && nombor <= 69 ){ | |
// return 'C' | |
// } else { | |
// return 'F' | |
// } | |
// }) | |
// let grade = [] | |
// markah.forEach(nombor => { | |
// switch (true) { | |
// case nombor >= 80: | |
// grade.push('A') | |
// break; | |
// case nombor >= 70 && nombor <= 79: | |
// grade.push('B') | |
// break | |
// case nombor >= 40 && nombor <= 69: | |
// grade.push('C') | |
// break | |
// default: | |
// grade.push('F') | |
// break; | |
// } | |
// }); | |
// console.log('grade ', grade) | |
// password generator | |
const perkataan ='abcdefghijklmnopqrstuvwxyz' | |
const nombor = '01234567890' | |
const simbol = '~!@#$%^&*()_+' | |
// tuliskan function yang menhasilkan random password mengabungkang perkataan, nombor dan symbol, | |
// jadikan panjang password tersebut 10 aksara | |
// kemasini function password generator tersebut supaya menerima beberapa parameters | |
// panjang | |
// include nombor? | |
// include simbol? | |
// pseudocode | |
// const combinedChar = perkataan + nombor + simbol | |
// // console.log(combinedChar) | |
// // console.log('total char', combinedChar.length) | |
// // randomly generate a number between 0 - 49 | |
// // Math.floor(Math.random() * 10); | |
// // function to select 10 characters randomly | |
function randomChar(combinedChar){ | |
const randomIndex = Math.floor(Math.random() * combinedChar.length) | |
return combinedChar[randomIndex] | |
} | |
// let password = '' | |
// for (let index = 0; index < 10; index++) { | |
// password += randomChar() | |
// } | |
// console.log(password) | |
function passwordGenerator(length, includeNumber=true, includeSymbol=true){ | |
let combinedChar = perkataan | |
if (includeNumber){ | |
combinedChar += nombor | |
} | |
if (includeSymbol){ | |
combinedChar += simbol | |
} | |
let password = '' | |
for (let index = 0; index < length; index++) { | |
password += randomChar(combinedChar) | |
} | |
return password | |
} | |
console.log(passwordGenerator(10, true, 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
const markah = [80, 99, 57, 40, 88, 39] | |
// kirakan purata | |
// dapatkan markah tertinggi | |
// dapatkan gred | |
// A = 80 --> 100 | |
// B = 70 --> 79 | |
// C = 40 --> 69 | |
// F = less than 40 | |
// eg =['A', 'A', 'C', 'C', 'A', 'F'] | |
// password generator | |
const perkataan ='abcdefghijklmnopqrstuvwxyz' | |
const nombor = '01234567890' | |
const simbol = '~!@#$%^&*()_+' | |
// tuliskan function yang menhasilkan random password mengabungkang perkataan, nombor dan symbol, | |
// jadikan panjang password tersebut 10 aksara | |
// eg $5we@#1g@ | |
// kemasini function password generator tersebut supaya menerima beberapa parameters | |
// panjang | |
// include nombor? | |
// include simbol? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment