Js Bedelliyeni
Js Bedelliyeni
Or
const arr = [1,2,3,4,5];
let sum=0;
for(let i=0;i<arr.length;i++) sum+=arr[i];
console.log(sum);
function checker(num){
if(num%2===0) return "even";
else return "odd";
}
console.log(checker(18));
12.
const head = document.getElementById("myHeading");
const txt = document.getElementsByTagName("p")[0];
checker("qarşida");
checker("radar");
checker("var");
19. const numbers = [12, 23, 45, 67, 34, 73];
a) Create a new array that contains the square of each number in
the numbers array. (4 points)
b) Create a new array that contains only the even numbers from
the numbers array. (4 points)
c) Find the sum of all the numbers in the numbers array. (4 points)
console.log(getDaysInMonth(3));
console.log(getDaysInMonth(8));
console.log(getDaysInMonth(2));
console.log(getDaysInMonth(13));
27. Write a JavaScript function to find the largest number in an
array.
function findbigger(nums) {
nums.sort(function(a,b){return a - b});
console.log(nums[nums.length - 1]);
}
findbigger([1, 7, 4, 6, 5]);
Or
function findbigger(nums) {
let max = nums[0];
for(let i = 1;i < nums.length;i++){
if(nums[i]>max) max = nums[i];
}
console.log(max);
}
findbigger([1, 7, 4, 6, 5]);
console.log(`${key}: ${obj[key]}`);
}
}
const myObject = {
surname: "Bedelli",
age: 30,
city: "Ismayilli-Basarkecher",
};
printObjectProperties(myObject);
Or
function printObjectProperties(obj) {
for (let key in obj) {
console.log(key + ": " + obj[key]);
}
}
const myObject = {
name: "Bedelli",
age: 30,
city: "Ismayilli-Basarkecher",
};
printObjectProperties(myObject);
d) Remove the second element from the main array and replace it
with '36'. (4 points).
const myarray = ["John", 30, true, ["dog", "cat"]];
myarray[1] = 36;
console.log(myarray);
(js)
const btn = document.querySelector(".btn");
const block = document.querySelector("#myElement");
let count = 0;
btn.addEventListener("click", () => {
if (block.style.opacity === "0") block.style.opacity = "1";
else block.style.opacity = "0";
});
OR
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"
/>
<title>Document</title>
<style>
#myElement {
width: 200px;
height: 200px;
background-color: blue;
opacity: 0;
}
</style>
</head>
<body>
<div id="myElement"></div>
<button class="btn" onclick="clicker">click</button>
<script src="index.js">
function clicker(){
const btn = document.querySelector(".btn");
const block = document.querySelector("#myElement");
if (block.style.opacity === "0") block.style.opacity = "1";
else block.style.opacity = "0";
}
</script>
</body>
</html>
45. Develop a JavaScript function that takes an array of strings
and returns a new array with each string's first letter
capitalized.
function letterCapitalized(s) {
let news = s.map((x) => {
return x[0].toUpperCase() + x.slice(1);
});
console.log(news);
}
letterCapitalized(["dostum", "murebbe", "isteyirsen?"]);
Or
function letterCapitalized(s) {
let newarr = [];
for (let i = 0; i < s.length; i++) {
newarr.push(s[i][0].toUpperCase() + s[i].slice(1));
}
console.log(newarr);
}
letterCapitalized(["dostum", "murebbe", "isteyirsen?"]);
Or
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"
/>
<title>Document</title>
</head>
<body>
<input class="inp" type="text" name="" id="" />
<button class="btn" onclick="colorchanger">click</button>
<script src="index.js">
const btn = document.querySelector(".btn");
const inp = document.querySelector(".inp");
function colorchanger(){
let val = inp.value;
document.body.style.backgroundColor = val;
}
</script>
</body>
</html>