Skip to content

Instantly share code, notes, and snippets.

@djoudi
Created March 10, 2023 15:11
Show Gist options
  • Save djoudi/17ea61e3c0bfc567a3dd7f7a6e82ec56 to your computer and use it in GitHub Desktop.
Save djoudi/17ea61e3c0bfc567a3dd7f7a6e82ec56 to your computer and use it in GitHub Desktop.
// variable with type
// const
// operation
// comparisation
// condition
//loop
//function
// ds
//dsfdfsdfdsf
/*
1 byte = 8 bit
*/
var x = 15
// azAZ$_
//azAZ_$09
//var _st_$3 = "Ecoin"
// number string boolean object array
var num1 = 25 // integer
var num2 = 36.9 //float
var num3 = 20195.98745 // double
var str1 = "Welcom to ecoin" // String
var str2 = 'A' // String char
var isAdmin = true //boolean bool
var isUser = false // boolean
//console.log(str1)
//console.log(num2)
var tab = [45, 36, "Ecoin", true, 2016]
//console.log(tab)
var tab2 = new Array(45, 36, 9, 8, 7)
//console.log(tab2)
var tab3 = new Array()
tab3[0] = "Ecoin"
tab3[1] = 28
tab3[2] = 2.66
tab3[3] = 203
tab3[4] = false
//console.log(tab3)
//console.log(typeof tab2)
var tab4 = [14, 36, "Ecoin", 2023]
tab4['test'] = 88
//console.log(tab4)
//Object
var student = { nom: "Ahmed", prenom: "kadri", age: 25 }
//console.log(student.age)
//console.log(typeof student.age)
const PI = 3.14
//console.log(PI)
const project = "Ecoin"
// + - * / %
var x = 25
/*
console.log(x + y)
console.log(x - y)
console.log(x * y)
console.log(y / x)
console.log(y % x)
*/
//x = x + 9 // x+=9
/*x += 9
console.log(x)
x = x - 9 // x-=6
x = x * 9 // x*=6
x = x / 9 // x/=6
*/
//x = x + 1 // x++ /incrementation
//x++ // x--
//console.log(++x) //25
//console.log(x++) //25
var a = 19
var b = 23
// == != > >= < <= ! ===
var t = a > b
//console.log(!t)
var c1 = 25
var c2 = "25"
//console.log(c1 === c2)
//console.log(true & true)
/*
true && true ===> true
true && false ===> false
false && true ===> false
false && false ===> false
true || true ===> true
true || false ===> true
false || true ===> true
false || false ===> false
*/
// condition nested if
/*var x = 45
if (x >35)
console.log("Yes");
else if (x > 25)
console.log("X > 25")
else
console.log("OK")
console.log("Ecoin")
*/
/*
var a1 = prompt("please enter number1")
a1 = parseInt(a1)
var a2 = prompt("please enter number2")
a2 = parseInt(a2)
if (a1 > a2) {
console.log("A1 > A2")
} else if(a1 < a2) {
console.log("A2 > A1")
} else {
console.log("A2 = A1")
}
*/
//console.log(typeof a1)
//a1 a2 a3 >=
/*
a, b, c
a >= b ==> t ==> a >= c
==> f ==> b >= c
*/
/*
var a = prompt("please enter number1")
a = parseInt(a)
var b = prompt("please enter number2")
b = parseInt(b)
var c = prompt("please enter number2")
c = parseInt(c)
if (a >= b ) {
if (a >= c) {
if(a%2==0) console.log(a+" is pair")
else console.log(a+" is impair")
} else {
if(c%2==0) console.log(c+" is pair")
else console.log(c+" is impair")
}
} else {
if (b >= c) {
if(b%2==0) console.log(b+" is pair")
else console.log(b+" is impair")
}else {
if(c%2==0) console.log(c+" is pair")
else console.log(c+" is impair")
}
}
*/
//loop
var i = 1
while (i<=5) {
console.log("Ecoin"+i)
i++
}
var j = 1
do {
console.log("JS "+j)
j++
}while(j<=10)
var t = []
var t2 = new Array()
var s = 0
while (s <= 4) {
t[s] = "Ecoin " + s
s++
}
console.log(t)
var s1 = 0
while (s1 <= 4) {
console.log(t[s1])
s1++
}
// for loop
for (var i = 0; i < 10; i++){
console.log("Ecoin "+i)
}
for (var j = 50; j > 0; j--){
console.log("Ecoin "+j)
}
var k = 50
while (k > 0) {
console.log("JAVASCRIPT " + k)
k--
}
var m = 50
do {
console.log("JAVASCRIPT " + m)
m--
} while (m > 0)
var arr = ["com", "com", "net", "org", "com", "dz", "com"] // 4
var s = "fr"
var cpt = 0
//console.log(s.length)
for (var i = 0; i < arr.length; i++){
//console.log(arr[i])
if (arr[i] == s)
cpt++
}
console.log(cpt)
var t = []
var w = ["Alger", "Blida", "Oran", "Batna"]
for (var i = 0; i < w.length; i++){
t[i] = w[i].length
console.log(t[i])
}
for (var i = 0; i < w.length; i++){
console.log(t[i])
}
// 0 1 2 3 4 5 6
tab = [45, 50, 9, 88, 5, 200, 7]
var max = tab[0]
for (var i = 0; i < tab.length; i++){
if (tab[i] >= max)
max = tab[i] //200
}
console.log(max)
var j = 1
while (j <= 5) {
console.log(j)
j++
}
var j = 1
do {
console.log(j)
j++
}while(j<=5)
for (var j = 1; j <= 5; j++){
console.log(j)
}
var j = 1
for (; ;){
if(j > 5) break
console.log(j)
j++
}
var x, y, z
x = 100
y = 6
z = x //z = 100
x = y //x = 6
y = z // y = 100
var ages = [15, 36, 5, 25, 9, 100, 45]
var i = 0
while (i < ages.length) {
i++
}
//7 execercice
// sort min max duplication counters length
//function
// var global - local
//var ages = [15, 36, 5, 25, 9, 100, 45]
/* var nom = "Ecoin"
var student = {nom:"ahmed",age:25,email:"[email protected]"}
console.log(ages.length)
console.log(nom.length)
console.log(student.email.length) */
/* var i = 0
while (i < ages.length) {
console.log(ages[i])
i++
}
console.log("============================");
var i = 0
do {
console.log(ages[i])
i++
}while(i< ages.length)
console.log("============================");
for (i = 0; i < ages.length; i++){
console.log(ages[i])
}
*/
var student = {nom:"ahmed",age:25,email:"[email protected]"}
/* for (a in student) {
console.log(student[a]);
} */
/* for (b of ages) {
console.log(b);
}
*/
var ages = [15, 36, 5, 25, 9, 100, 45] // 5 9 15 25 36 45 100
/*console.log(ages);
ages.sort()
console.log(ages);*/
/* var sort = []
var p = 0
var s = 0
for (var j = 0; j < ages.length; j++) {
var min = 99999999999999
for (var i = 0; i < ages.length; i++) {
if (min>=ages[i] && ages[i]!=-1) {
min = ages[i] //15 5 // 15 9
s = i // 0 2 // 0 4
}
}
ages[s] = -1
sort[j] = min
}
console.log(ages);
console.log(sort); */
//7 execercice
// sort min max duplication counters length
//function
// var global - local
function sum(a,b) {
return a + b
}
var res = sum(8, 3)
//console.log(res);
function calc(a, b, op) {
switch (op) {
case '+':
console.log(a + b)
break
case '-':
console.log(a - b)
break
case '*':
console.log(a * b)
break
case '/':
console.log(a / b)
break
default:
console.log("No operation");
break
}
}
//calc(18,3,"+")
//c = "t"
//var nom = "Welcom to Ecoin" ==> true
function checkChar(nom, c) {
var st = {
ischeck: false,
cpt: 0
}
for (var i = 0; i < nom.length; i++) {
if (nom[i] == c) {
st.ischeck = true
st.cpt++
}
}
return st
}
result = checkChar("This is Javascript",'i')
//console.log("the char is "+result.ischeck+ " Cpt = "+result.cpt);
var tab = [45, 36, 9, 8, 8, 14]
console.log(tab);
tab.push(99)
console.log(tab);
tab.pop()
tab.pop()
tab.push(155)
//console.log(tab.indexOf(100));
var t1 = [36, 36, 36,36,25, 8, 25, 14]
function removeT(t) {
var sec = [] // 45 36 9 25
for (i = 0; i < t.length; i++){
var v = t[i]
if (sec.indexOf(v) < 0) {
sec.push(v)
}
}
return sec
}
console.log(removeT(t1));
var t2 = [5, 88, true, 36, 25, "A", 100, "C"]
//[5,88,10,36,25,100]//
function noChar(t) {
var sec = []
for (i = 0; i < t.length; i++){
var v = t[i]
if (typeof v == "number") {
sec.push(v)
}
}
return sec
}
console.log(noChar(t2));
//let block variable
//var fun vari
var t3 = 49 //global
if (true) {
let s1 = 45 // local
var s2 = 55 // global
console.log(s1);//45
console.log(s2);//55
}
//console.log(s1);//45
console.log(s2);//55
/* function ecoin() {
let s1 = 66
let s2 = 100 //local
console.log(s1); //66
console.log(s2); //100
}
ecoin()
console.log(s1);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment