day 2 finished.

pull/151/head
eraygundogmus 5 years ago
parent 84cbb25d36
commit 16f8f6c884

@ -263,3 +263,84 @@ myFunct(str1,str2)
//7
const num = Math.random() * 251
// if integer
const num2 = Math.floor(Math.random()*251)
//8
function getRandomInt(min,max) {
min = Math.ceil(min)
max = Math.floor(max)
return Math.floor(Math.random() * (max - min) + min)
}
getRandomInt(50,100)
//9
function getRandomInt(min,max) {
min = Math.ceil(min)
max = Math.floor(max)
return Math.floor(Math.random() * (max - min) + min)
}
getRandomInt(0,255)
//10
const txt = 'JavaScript'
function getRandLetFromTxt (a) {
const txtLong = a.length - 1
const getRand = Math.floor(Math.random() * (txtLong + 1))
return a.charAt(getRand)
}
getRandLetFromTxt(txt) // gets a random string character in text :)
//11
console.log('1 1 1 1 1\n2 1 2 4 8\n3 1 3 9 27\n4 1 4 16 64\n5 1 5 25 125')
//12
const aTxt = 'You cannot end a sentence with because because because is a conjunction'
console.log(aTxt.indexOf('b')) // 31
console.log(aTxt.lastIndexOf('e')) // 54
console.log(aTxt.substr(31,23))
// Exercises: Level 3
//1
const anyTxt = 'Love is the best thing in this world. Some found their love and some are still looking for their love.'
console.log(anyTxt.match(/love/gi))
//2
console.log(aTxt.match(/because/gi))
// that was unnecessarily hard to find how to escape $ but it's \ i guess
const sentence = '%I $am@% a %tea@cher%, &and& I lo%#ve %te@a@ching%;. The@re $is no@th@ing; &as& mo@re rewarding as educa@ting &and& @emp%o@weri@ng peo@ple. ;I found tea@ching m%o@re interesting tha@n any ot#her %jo@bs. %Do@es thi%s mo@tiv#ate yo@u to be a tea@cher!? %Th#is 30#Days&OfJavaScript &is al@so $the $resu@lt of &love& of tea&ching'
console.log(sentence.replace(/%|@|#|&|\$|!|;/gim,''))
// 4
const myTxt = 'He earns 5000 euro from salary per month, 10000 euro annual bonus, 15000 euro online courses per month.'
const sumSalary = (a) => {
let arr = a.match(/\d{2,10}/gi)
let summary = 0
const strToNum = arr.map((i) => Number(i));
for (i=0; i <= arr.length - 1; i++) {
summary += strToNum[i] }
return summary
}
sumSalary(myTxt) // 30000

Loading…
Cancel
Save