javascript sample programs code example
Example 1: sample in javascript
function sample(arr, req) {
arr = arr.sort(()=>{ return 0.5 - Math.random() }) ;
let i = 0,
array = [];
while (i < req) {
array.push(arr[i])
++i
}
return array
}
let arr = [1,2,3 ,4,5] ;
console.log( sample(arr , 2) )
Example 2: javascript examples
const num1 = parseInt(prompt('Enter the first number '));
const num2 = parseInt(prompt('Enter the second number '));
const sum = num1 + num2;
console.log(`The sum of ${num1} and ${num2} is ${sum}`);