Today I made a JS script to create a json file
with the KEY, SYN, ANT for the following book:
A COMPLETE DICTIONARY OF Synonyms and
Antonyms, 1898 BY The Rt. Rev. Samuel
Fallows, A.M., B.D.
Script:
RESULT
const fs = require('fs');
const readline = require('readline');
const fileStream = fs.createReadStream('SYNANT.html');
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});
let SYNANT = {}
let lastKeyIndex = -1, index = -1, Key, Syn, Ant
rl.on('line', (line) => {
index += 1
if(line.includes("KEY: ")){
lastKeyIndex = index
}
if(lastKeyIndex == index){
Key = generateValue(line)
Key.replace(/[^a-zA-Z]/g, '')
}else if(lastKeyIndex + 1 == index){
Syn = generateValue(line)
}else if(lastKeyIndex + 2 == index){
Ant = generateValue(line)
SYNANT[Key] = {SYN : Syn, ANT: Ant}
}
});
rl.on('close', () => {
let json = JSON.stringify(SYNANT, null, 4);
fs.writeFile(
"SYNANT.json",
json,
err => {
if (err) throw err;
});
console.log("Done writing");
});
function generateValue(line){
let key = ""
let add = false
for(let i = 1; i < line.length; i++){
if(line[i - 1] == " ")
add = true
if(line[i] == ".")
add = false
if(add)
key += line[i]
}
return key.trim()
}
I'M JAVASCRIPT!
I'M JAVASCRIPT WITH EXTERNAL
<!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>
I'M JAVASCRIPT
</body>
</html>
<script>
alert("I AM JAVASCRIPT!")
</script>
INDEX.HTML
INDEX.JS
<!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>
I'M JAVASCRIPT
</body>
</html>
<script src="./index.js">
</script>
WORKING WITH LETTERS
alert("I AM JAVASCRIPT")
GIVING THE RIGHT NAME
let newName = 'John';
let admin = newName;
console.log(admin)
UPPERCASE OR CONST?
// Create a variable with the name of our planet. How would you name such a variable?
let ourPlanet = "Earth";
// Create a variable to store the name of a current visitor to a website. How would you name that variable?
let newVisitor = "John"
STRING QUOTES
// Here we have a constant birthday for the date, and also the age constant.
// The age is calculated from birthday using someCode(), which means a function call that we didn’t explain yet (we will soon!), but the details don’t matter here, the point is that age is calculated somehow based on the birthday.
// Would it be right to use upper case for birthday? For age? Or even for both?
const BIRTHDAY = '18.04.1982'; // make birthday uppercase because it's a known value
const AGE = someCode(BIRTHDAY); // make age camelCase because its value is'nt know before execution?
A SIMLE PAGE!
// What is the output of the script?
let newName = "Ilya";
console.log( `hello ${1}` ); // hello 1
console.log( `hello ${"name"}` ); // hello name
console.log( `hello ${newName}` ); // hello Ilya
THE POSTFIX AND PREFIX FORMS
let visitor_name = prompt('Pls enter your name sir!');
alert(`Your name is ${visitor_name}`);
ASSIGNMENT RESULT
let a = 1, b = 1;
let c = ++a;
let d = b++;
// a = 2, b = 2, c = 2, d = 1
console.log(a, b, c, d)
TYPE CONVERSIONS
let a = 2;
let x = 1 + (a *= 2);
// a = 4, x = 5
console.log(a, x)
FIX THE ADDITION
console.log("" + 1 + 0); // 10
console.log("" - 1 + 0); // -1
console.log(true + false); // 1
console.log(6 / "3"); // 2
console.log("2" * "3"); // 6
console.log(4 + 5 + "px"); // 9px
console.log("$" + 4 + 5); // $45
console.log("4" - 2); // 2
console.log("4px" - 2); // Nan
console.log(" -9 " + 5); // -9 5
console.log(" -9 " - 5); // -14
console.log(null + 1); // 1
console.log(undefined + 1); // Nan
console.log(" \t \n" - 2 ); // -2
// Here’s a code that asks the user for two numbers and shows their sum.
// It works incorrectly. The output in the example below is 12 (for default prompt values).
// Why? Fix it. The result should be 3.
// ORIGINAL CODE:
let a = prompt("First number?", 1);
let b = prompt("Second number?", 2);
alert(a + b); // 12
// BY USING UNARY PLUS I CAN CONVERT THE STRINGS TO NUMBERS
let a = prompt("First number?", 1);
let b = prompt("Second number?", 2);
alert(+a + +b); // 12