// #5 Js function
// js function which takes any value and shows them
function show(value){
console.log(value)
}
// call show function with hello value
show("Hello")
// @jsCode0
// js function which takes any value and shows them
function show(value){
console.log(value)
}
// call show function with hello value
show("Hello")
// @jsCode0
// strings declaration in js
let str = "its js strings"
console.log(str)
let str = "its js strings"
console.log(str)
// integer declaration in js
let num = 76
console.log(num)
let num = 76
console.log(num)
// operation in integer in js
let int1 = 50
let int2 = 8
console.log("Given values ", int1, " and ", int2)
console.log("\nSubtraction: ", int1 - int2)
console.log("Addition: ", int1 + int2)
console.log("Multiplication: ", int1 * int2)
console.log("division: ", int1 / int2)
// @jsCode0
let int1 = 50
let int2 = 8
console.log("Given values ", int1, " and ", int2)
console.log("\nSubtraction: ", int1 - int2)
console.log("Addition: ", int1 + int2)
console.log("Multiplication: ", int1 * int2)
console.log("division: ", int1 / int2)
// @jsCode0
// operation in float in js
let num1 = 50.5
let num2 = 8.3
console.log("Given values ", num1, " and ", num2)
console.log("\nSubtraction: ", num1 - num2)
console.log("Addition: ", num1 + num2)
console.log("Multiplication: ", num1 * num2)
console.log("division: ", num1 / num2)
// @jsCode0
let num1 = 50.5
let num2 = 8.3
console.log("Given values ", num1, " and ", num2)
console.log("\nSubtraction: ", num1 - num2)
console.log("Addition: ", num1 + num2)
console.log("Multiplication: ", num1 * num2)
console.log("division: ", num1 / num2)
// @jsCode0
// List means array but with some difference
// Creating a List
let my_list = [];
console.log("Empty list:", my_list);
my_list = [1, 2, 3, 4, 5];
console.log("List with initial values:", my_list);
// Accessing List Elements
let element = my_list[0];
console.log("Element at index 0:", element);
let last_element = my_list[my_list.length - 1];
console.log("Last element:", last_element);
// Modifying List Elements
my_list[2] = 10;
console.log("List after updating element at index 2:", my_list);
// Adding Elements to the List
my_list.push(6);
console.log("List after appending element:", my_list);
my_list.splice(3, 0, 7);
console.log("List after inserting element at index 3:", my_list);
let another_list = [8, 9, 10];
my_list = my_list.concat(another_list);
console.log("List after extending with another list:", my_list);
// Removing Elements from the List
my_list = my_list.filter(item => item !== 4);
console.log("List after removing element 4:", my_list);
let removed_element = my_list.splice(2, 1);
console.log("List after removing element at index 2:", my_list);
console.log("Removed element:", removed_element[0]);
// Clear list
my_list = [];
console.log("List after clearing all elements:", my_list);
another_list = [8, 9, 10, 5, 7, 3, 9];
my_list = my_list.concat(another_list);
console.log("List after extending with another list:", my_list);
// Slicing a List
let sliced_list = my_list.slice(1, 3);
console.log("Sliced list from index 1 to 3 (exclusive):", sliced_list);
// sub_list
let sub_list = my_list.slice(2);
console.log("Sublist from index 2 till the end:", sub_list);
// reversed_list
let reversed_list = my_list.reverse();
console.log("Reversed list:", reversed_list);
// List Iteration
my_list.forEach(element => {
console.log("Element:", element);
});
my_list.forEach((element, index) => {
console.log("Index:", index, "Element:", element);
});
// Code by @Python_Codes_Pro
// buttons by @IOChannel_bot
// Run by @Compiler0bot
// for Group @CodeCompiler_Bot
// Creating a List
let my_list = [];
console.log("Empty list:", my_list);
my_list = [1, 2, 3, 4, 5];
console.log("List with initial values:", my_list);
// Accessing List Elements
let element = my_list[0];
console.log("Element at index 0:", element);
let last_element = my_list[my_list.length - 1];
console.log("Last element:", last_element);
// Modifying List Elements
my_list[2] = 10;
console.log("List after updating element at index 2:", my_list);
// Adding Elements to the List
my_list.push(6);
console.log("List after appending element:", my_list);
my_list.splice(3, 0, 7);
console.log("List after inserting element at index 3:", my_list);
let another_list = [8, 9, 10];
my_list = my_list.concat(another_list);
console.log("List after extending with another list:", my_list);
// Removing Elements from the List
my_list = my_list.filter(item => item !== 4);
console.log("List after removing element 4:", my_list);
let removed_element = my_list.splice(2, 1);
console.log("List after removing element at index 2:", my_list);
console.log("Removed element:", removed_element[0]);
// Clear list
my_list = [];
console.log("List after clearing all elements:", my_list);
another_list = [8, 9, 10, 5, 7, 3, 9];
my_list = my_list.concat(another_list);
console.log("List after extending with another list:", my_list);
// Slicing a List
let sliced_list = my_list.slice(1, 3);
console.log("Sliced list from index 1 to 3 (exclusive):", sliced_list);
// sub_list
let sub_list = my_list.slice(2);
console.log("Sublist from index 2 till the end:", sub_list);
// reversed_list
let reversed_list = my_list.reverse();
console.log("Reversed list:", reversed_list);
// List Iteration
my_list.forEach(element => {
console.log("Element:", element);
});
my_list.forEach((element, index) => {
console.log("Index:", index, "Element:", element);
});
// Code by @Python_Codes_Pro
// buttons by @IOChannel_bot
// Run by @Compiler0bot
// for Group @CodeCompiler_Bot
👍1
Learn about list many methods given above 👆you can run it by run button
List is a type of array in js
List is a type of array in js
let a = require('axios');
let url = "https://example.com";
let e = " excecuted"
a.get(url).then(r => console.log(0+e));
a.get(url).then(r => console.log(1+e));
a.get(url).then(r => console.log(2+e));
a.get(url).then(r => console.log(3+e));
a.get(url).then(r => console.log(4+e));
// this code demonstrates asynchronous programming here any line of code can be excecuted first
let url = "https://example.com";
let e = " excecuted"
a.get(url).then(r => console.log(0+e));
a.get(url).then(r => console.log(1+e));
a.get(url).then(r => console.log(2+e));
a.get(url).then(r => console.log(3+e));
a.get(url).then(r => console.log(4+e));
// this code demonstrates asynchronous programming here any line of code can be excecuted first
// get lyrics of any song
require('axios')
.get('https://song.panditsiddharth.repl.co/lyrics?song=ram+siya+ram')
.then(r=>console.log(r.data))
// @jsCode0
require('axios')
.get('https://song.panditsiddharth.repl.co/lyrics?song=ram+siya+ram')
.then(r=>console.log(r.data))
// @jsCode0
😱1
// Curried function
function multiply(a) {
return function(b) {
return a * b;
}
}
// Curried function can be used with partial application
const multiplyByTwo = multiply(2);
console.log(multiplyByTwo(4)); // Output: 8
// Or it can be invoked with all arguments at once
console.log(multiply(3)(5));
// @jscode0
function multiply(a) {
return function(b) {
return a * b;
}
}
// Curried function can be used with partial application
const multiplyByTwo = multiply(2);
console.log(multiplyByTwo(4)); // Output: 8
// Or it can be invoked with all arguments at once
console.log(multiply(3)(5));
// @jscode0
String functions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
@jscode0 #share #support
1.
length: Returns the length of a string.2.
toUpperCase(): Converts a string to uppercase.3.
toLowerCase(): Converts a string to lowercase.4.
indexOf(searchValue, startIndex): Returns the index of the first occurrence of a specified value in a string, starting from the specified index.5.
lastIndexOf(searchValue, startIndex): Returns the index of the last occurrence of a specified value in a string, starting from the specified index.6.
substring(startIndex, endIndex): Extracts a substring from a string, between the specified start and end indexes.7.
slice(startIndex, endIndex): Extracts a section of a string and returns a new string, between the specified start and end indexes.8.
replace(searchValue, replaceValue): Replaces occurrences of specified value with another value in a string.9.
split(separator): Splits a string into an array of substrings based on the specified separator.10.
trim(): Removes whitespace from both ends of a string.11.
startsWith(searchValue, startIndex): Returns true if a string starts with the specified value; otherwise, returns false.12.
endsWith(searchValue, endIndex): Returns true if a string ends with the specified value; otherwise, returns false.13.
charAt(index): Returns the character at the specified index of a string.14.
concat(str1, str2, ...): Concatenates two or more strings and returns a new string.15.
includes(searchValue, startIndex): Returns true if a string contains the specified value; otherwise, returns false.16.
match(regex): Searches a string for a match against a regular expression and returns an array of matches.@jscode0 #share #support
// fetch song link
require("axios").get("https://song.panditsiddharth.repl.co/song?song=ae+watan")
.then((e)=>{console.log(e.data)})
require("axios").get("https://song.panditsiddharth.repl.co/song?song=ae+watan")
.then((e)=>{console.log(e.data)})
// fetch song lyrics
let url = "https://song.panditsiddharth.repl.co/lyrics?song=ae+watan"
require("axios").get(url)
.then((e)=>{console.log(e.data)})
let url = "https://song.panditsiddharth.repl.co/lyrics?song=ae+watan"
require("axios").get(url)
.then((e)=>{console.log(e.data)})
// run it and see its result and shareit
const message = String.fromCodePoint(32, 72, 97, 112, 112, 121, 32, 73, 110, 100, 101, 112, 101, 110, 100, 101, 110, 99, 101, 32, 100, 97, 121, 33);
console.log('\u{1F1EE}\u{1F1F3}' + message);
// @jscode0
const message = String.fromCodePoint(32, 72, 97, 112, 112, 121, 32, 73, 110, 100, 101, 112, 101, 110, 100, 101, 110, 99, 101, 32, 100, 97, 121, 33);
console.log('\u{1F1EE}\u{1F1F3}' + message);
// @jscode0
// Decimal integer to binary number
function integer(intgr) {
if (intgr < 1)
return 0;
console.log("Now dividing decimal by 2: ")
let temp = "";
while (intgr > 0) {
console.log(intgr + "/2 reminder " + intgr % 2);
temp += intgr % 2;
intgr = Math.floor(intgr / 2);
}
const reversedStr = temp.split("").reverse().join("");
return reversedStr;
}
let dcml = 10;
let intgr = Math.floor(dcml);
console.log("Given decimal " + dcml + "\n");
console.log("\nBinary is " + integer(intgr));
function integer(intgr) {
if (intgr < 1)
return 0;
console.log("Now dividing decimal by 2: ")
let temp = "";
while (intgr > 0) {
console.log(intgr + "/2 reminder " + intgr % 2);
temp += intgr % 2;
intgr = Math.floor(intgr / 2);
}
const reversedStr = temp.split("").reverse().join("");
return reversedStr;
}
let dcml = 10;
let intgr = Math.floor(dcml);
console.log("Given decimal " + dcml + "\n");
console.log("\nBinary is " + integer(intgr));
// Decimal to binary conversion with steps shown
function frac(frk) {
if (frk === 0) {
return 0;
}
console.log("\nNow multiplying fractional part by 2");
let i = 0;
let binary = "";
while (frk != 0 && i < 7) {
console.log(frk + " x 2 integer " + Math.floor(frk * 2));
frk = frk * 2;
let k = Math.floor(frk);
binary += k;
frk = (frk - k).toFixed(5);
i++;
}
return binary;
}
function integer(intgr) {
if (intgr < 1) {
return 0;
}
console.log("Now dividing integer part by 2: ");
let temp = "";
while (intgr > 0) {
console.log(intgr + "/2 reminder " + intgr % 2);
temp += intgr % 2;
intgr = Math.floor(intgr / 2);
}
const reversedStr = temp.split("").reverse().join("");
return reversedStr;
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter decimal number: ', (input) => {
let dcml = input;
let intgr = Math.floor(dcml);
let frk = (dcml - intgr).toFixed(6);
console.log("Given decimal " + dcml + "\n");
if (frk == 0) {
console.log("\nBinary is " + integer(intgr));
} else {
console.log("First we divide this number into two parts: integer and fractional part.\n" + dcml + " = " + intgr + " + " + frk + "\n");
console.log("\nAfter adding both parts:\nBinary is " + integer(intgr) + (frk != 0 ? ("." + frac(frk)) : ""));
}
rl.close();
});
// @jsCode0
function frac(frk) {
if (frk === 0) {
return 0;
}
console.log("\nNow multiplying fractional part by 2");
let i = 0;
let binary = "";
while (frk != 0 && i < 7) {
console.log(frk + " x 2 integer " + Math.floor(frk * 2));
frk = frk * 2;
let k = Math.floor(frk);
binary += k;
frk = (frk - k).toFixed(5);
i++;
}
return binary;
}
function integer(intgr) {
if (intgr < 1) {
return 0;
}
console.log("Now dividing integer part by 2: ");
let temp = "";
while (intgr > 0) {
console.log(intgr + "/2 reminder " + intgr % 2);
temp += intgr % 2;
intgr = Math.floor(intgr / 2);
}
const reversedStr = temp.split("").reverse().join("");
return reversedStr;
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter decimal number: ', (input) => {
let dcml = input;
let intgr = Math.floor(dcml);
let frk = (dcml - intgr).toFixed(6);
console.log("Given decimal " + dcml + "\n");
if (frk == 0) {
console.log("\nBinary is " + integer(intgr));
} else {
console.log("First we divide this number into two parts: integer and fractional part.\n" + dcml + " = " + intgr + " + " + frk + "\n");
console.log("\nAfter adding both parts:\nBinary is " + integer(intgr) + (frk != 0 ? ("." + frac(frk)) : ""));
}
rl.close();
});
// @jsCode0
// Decimal to Octal conversion with steps shown
function frac(frk) {
if (frk === 0) {
return 0;
}
console.log("\nNow multiplying fractional part by 8");
let i = 0;
let binary = "";
while (frk != 0 && i < 7) {
console.log(frk + " x 8 integer " + Math.floor(frk * 8));
frk = frk * 8;
let k = Math.floor(frk);
binary += k;
frk = (frk - k).toFixed(5);
i++;
}
return binary;
}
function integer(intgr) {
if (intgr < 1) {
return 0;
}
console.log("Now dividing integer part by 8: ");
let temp = "";
while (intgr > 0) {
console.log(intgr + "/8 reminder " + intgr % 8);
temp += intgr % 8;
intgr = Math.floor(intgr / 8);
}
const reversedStr = temp.split("").reverse().join("");
return reversedStr;
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter decimal number: ', (input) => {
let dcml = input;
let intgr = Math.floor(dcml);
let frk = (dcml - intgr).toFixed(6);
console.log("Given decimal " + dcml + "\n");
if (frk == 0) {
console.log("\nOctal is " + integer(intgr));
} else {
console.log("First we divide this number into two parts: integer and fractional part.\n" + dcml + " = " + intgr + " + " + frk + "\n");
console.log("\nAfter adding both parts:\nOctal is " + integer(intgr) + (frk != 0 ? ("." + frac(frk)) : ""));
}
rl.close();
}); // @jscode0
function frac(frk) {
if (frk === 0) {
return 0;
}
console.log("\nNow multiplying fractional part by 8");
let i = 0;
let binary = "";
while (frk != 0 && i < 7) {
console.log(frk + " x 8 integer " + Math.floor(frk * 8));
frk = frk * 8;
let k = Math.floor(frk);
binary += k;
frk = (frk - k).toFixed(5);
i++;
}
return binary;
}
function integer(intgr) {
if (intgr < 1) {
return 0;
}
console.log("Now dividing integer part by 8: ");
let temp = "";
while (intgr > 0) {
console.log(intgr + "/8 reminder " + intgr % 8);
temp += intgr % 8;
intgr = Math.floor(intgr / 8);
}
const reversedStr = temp.split("").reverse().join("");
return reversedStr;
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter decimal number: ', (input) => {
let dcml = input;
let intgr = Math.floor(dcml);
let frk = (dcml - intgr).toFixed(6);
console.log("Given decimal " + dcml + "\n");
if (frk == 0) {
console.log("\nOctal is " + integer(intgr));
} else {
console.log("First we divide this number into two parts: integer and fractional part.\n" + dcml + " = " + intgr + " + " + frk + "\n");
console.log("\nAfter adding both parts:\nOctal is " + integer(intgr) + (frk != 0 ? ("." + frac(frk)) : ""));
}
rl.close();
}); // @jscode0
// Decimal to Hexadecimal conversion with steps shown
function hex(ele){
switch(ele){
case 10: ele = "A"; break;
case 11: ele = "B"; break;
case 12: ele = "C"; break;
case 13: ele = "D"; break;
case 14: ele = "E"; break;
case 15: ele = "F"; break;
}
return ele;
}
function frac(frk) {
if (frk === 0) {
return 0;
}
console.log("\nNow multiplying fractional part by 16");
let i = 0;
let hex = "";
while (frk != 0 && i < 7) {
console.log(frk + " x 16 integer " + Math.floor(frk * 16));
frk = frk * 16;
let k = Math.floor(frk);
hex += k;
frk = (frk - k).toFixed(5);
i++;
}
return hex;
}
function integer(intgr) {
if (intgr < 1) {
return 0;
}
console.log("Now dividing integer part by 16: ");
let temp = "";
let arr1 = []
// let arr2 = []
let i = 0;
while (intgr > 0) {
let hx = hex(intgr % 16)
console.log(intgr + "/16 reminder " + hx);
arr1[i++] = hx;
intgr = Math.floor(intgr / 16);
}
const reversedStr = arr1.reverse().join("");
return reversedStr;
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter decimal number: ', (input) => {
let dcml = input;
let intgr = Math.floor(dcml);
let frk = (dcml - intgr).toFixed(6);
console.log("Given decimal " + dcml + "\n");
if (frk == 0) {
console.log("\nHexadecimal is " + integer(intgr));
} else {
console.log("First we divide this number into two parts: integer and fractional part.\n" + dcml + " = " + intgr + " + " + frk + "\n");
console.log("\nAfter adding both parts:\nHexadecimal is " + integer(intgr) + (frk != 0 ? ("." + frac(frk)) : ""));
}
rl.close();
}); // @jscode0
function hex(ele){
switch(ele){
case 10: ele = "A"; break;
case 11: ele = "B"; break;
case 12: ele = "C"; break;
case 13: ele = "D"; break;
case 14: ele = "E"; break;
case 15: ele = "F"; break;
}
return ele;
}
function frac(frk) {
if (frk === 0) {
return 0;
}
console.log("\nNow multiplying fractional part by 16");
let i = 0;
let hex = "";
while (frk != 0 && i < 7) {
console.log(frk + " x 16 integer " + Math.floor(frk * 16));
frk = frk * 16;
let k = Math.floor(frk);
hex += k;
frk = (frk - k).toFixed(5);
i++;
}
return hex;
}
function integer(intgr) {
if (intgr < 1) {
return 0;
}
console.log("Now dividing integer part by 16: ");
let temp = "";
let arr1 = []
// let arr2 = []
let i = 0;
while (intgr > 0) {
let hx = hex(intgr % 16)
console.log(intgr + "/16 reminder " + hx);
arr1[i++] = hx;
intgr = Math.floor(intgr / 16);
}
const reversedStr = arr1.reverse().join("");
return reversedStr;
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter decimal number: ', (input) => {
let dcml = input;
let intgr = Math.floor(dcml);
let frk = (dcml - intgr).toFixed(6);
console.log("Given decimal " + dcml + "\n");
if (frk == 0) {
console.log("\nHexadecimal is " + integer(intgr));
} else {
console.log("First we divide this number into two parts: integer and fractional part.\n" + dcml + " = " + intgr + " + " + frk + "\n");
console.log("\nAfter adding both parts:\nHexadecimal is " + integer(intgr) + (frk != 0 ? ("." + frac(frk)) : ""));
}
rl.close();
}); // @jscode0
👍1
// Octal to binary conversion with steps
function loop(oct){
let bin = ""
for(let i = 0; i < oct.length; i++){
let a = parseInt(oct[i], 8).toString(2).padStart(3, '0')
console.log( oct[i] + " = " + a);
bin += a
}
return bin
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter Octal number: ', (input) => {
let oct = "" + input
for(let i = 0; i < oct.length; i++){
if(oct[i] > '7' || oct[i] < '0')
if(oct[i] != '.')
return console.log(oct + " is not a correct octal num")
}
console.log( "Given octal number: " + oct +"\n");
if(oct.includes(".")){
let ar = oct.split(".")
console.log( "Equivalent binary numbers for each octal number: ");
console.log( "\nNow After placing each binary in sequence: \n\nOctal " + oct + " in binary is " + loop(ar[0]) + "." + loop(ar[1]));
} else {
console.log( "Equivalent binary numbers for each octal number: ");
console.log( "\nNow After placing each binary in sequence: \n\nOctal " + oct + " in binary is " + loop(oct));
}
rl.close();
}) // @JsCode0
function loop(oct){
let bin = ""
for(let i = 0; i < oct.length; i++){
let a = parseInt(oct[i], 8).toString(2).padStart(3, '0')
console.log( oct[i] + " = " + a);
bin += a
}
return bin
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter Octal number: ', (input) => {
let oct = "" + input
for(let i = 0; i < oct.length; i++){
if(oct[i] > '7' || oct[i] < '0')
if(oct[i] != '.')
return console.log(oct + " is not a correct octal num")
}
console.log( "Given octal number: " + oct +"\n");
if(oct.includes(".")){
let ar = oct.split(".")
console.log( "Equivalent binary numbers for each octal number: ");
console.log( "\nNow After placing each binary in sequence: \n\nOctal " + oct + " in binary is " + loop(ar[0]) + "." + loop(ar[1]));
} else {
console.log( "Equivalent binary numbers for each octal number: ");
console.log( "\nNow After placing each binary in sequence: \n\nOctal " + oct + " in binary is " + loop(oct));
}
rl.close();
}) // @JsCode0