diff --git a/10.JS_Basics/index.html b/10.JS_Basics/index.html new file mode 100644 index 0000000..7a6770c --- /dev/null +++ b/10.JS_Basics/index.html @@ -0,0 +1,14 @@ + + + + + + + JS Basics + + + + + + + \ No newline at end of file diff --git a/10.JS_Basics/index.js b/10.JS_Basics/index.js new file mode 100644 index 0000000..7b7a3b1 --- /dev/null +++ b/10.JS_Basics/index.js @@ -0,0 +1,91 @@ +console.log("---------------------Section 1 - Play with variables------------------------") +console.log(1+2); +console.log("apple"+"orange"); + +console.log(1+2+"apple"); +console.log("apple"+1+2); + +console.log(1+true); + +console.log(0 == false); +console.log(1 === true); +console.log(2 == "2"); + +console.log("\n---------------------Section 2 - Play with Arrays------------------------") +cricketTeam = ["Dhoni","Kholi","Raina","Jadeja","Bumrah","Natraj","Bhuvi","Ashwin","Rishab","KL Rahul","Gill"] +console.log("Playing 11 ready \n" + cricketTeam) //create team 11 + +console.log("Oops! Captain -- "+cricketTeam.shift()+ " got injured" ) //remove first +console.log("Now we are a team of -- "+cricketTeam.length) //length +cricketTeam.push("Sanju") //add new element +console.log("New player joined -- "+ cricketTeam[10]) +cricketTeam.sort() //sort +console.log("In ascending order of names\n" + cricketTeam) + +//assiging random jersy number +team = {} +uniqueJerseyNumbers = []; +while(uniqueJerseyNumbers.length <11){ + number = Math.floor(Math.random() * 1000); + if(number>0) + uniqueJerseyNumbers.push(number); +} +for(i=0;i<11;i++){ + team[cricketTeam[i]] = uniqueJerseyNumbers[i]; +} +console.log("Players with their jersey number\n"); +console.log(team); + +//store in new array with uppercase names +upperCaseNames = cricketTeam.map(changeCase); +function changeCase(val){ + return val.toUpperCase(); +} +console.log("Upper Case name list\n"); +console.log(upperCaseNames); + + +console.log("\n---------------------Section 3 - Play with functions------------------------") +//1. display between a range +display(1,3); +function display(minValue, maxValue){ + for(i=minValue;i<=maxValue;console.log(i),i++); +} + +//2. format a date +today = new Date(); +format(today); +function format(today){ + console.log("Formatted Date is "+ today.getDate()+"/"+today.getMonth()+"/"+today.getFullYear()); + //console.log(typeof(today)+" "+typeof(today.getDate())); +} + +//3. celcius to fahrenheit conversion +convert_temperature(30); +function convert_temperature(celcius){ + fahrenheit = (celcius*1.80)+32; + console.log(fahrenheit+"°F"); +} + +//4. find average +scores = {"html" :100, "css" : 90, "js" :80}; +average = (marks)=> { + n = marks.length; + sum=0; + for(i=0;i= 0){ + ansString+=str[n]; + } + console.log(str+"'s reversed string is "+ansString); +} +targetString = "Sirius"; +reversedString = reverse(targetString); \ No newline at end of file