Skip to content

Commit

Permalink
Javascript Learning Continue
Browse files Browse the repository at this point in the history
Okay now I have finished the TASK part
It contains 5 task: Each of them is a beginner concept and I feel very
inclined to try this again to improve my learning
Task 1: if a string with zero, what boolean conversion ("0") will turn
into => True
Task 2: The name of Javascript (Just a simple if else conditional
expression)
Task 3: Show the sign (Simple and just include else if into the code)
Task 4: Rewrite 'if' into '?' (if..else into (condition) ? value1 :
value2
Task 5: Rewrite 'if..else..elseif' into '? and :' (So this is just the
same as task 4 but enhanced with else if)
--End of commit--
  • Loading branch information
thorgan376 committed Oct 19, 2023
1 parent b2cb3c3 commit 90cabac
Showing 1 changed file with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,75 @@ if (company == 'Netscape') {
*/

/*Our eyes scan the code verticaly. Code blocks which span several lines
are easier to understand than a long, horizontal instruction set.*/
are easier to understand than a long, horizontal instruction set.*/

//TASKs:
//TASK 1:
console.log(` TASKS:`);
console.log(` TASK 1: if (a string with zero)`);
//Will console.log be shown ?
if("0") {
console.log(`Hello "0" == true`);
}//True => Shown => Correct

//TASK2:
console.log(` TASK 2: The name of Javascript:`);
/*Using the if..else construct, write the code which asks: ‘What is the “official” name of JavaScript?’
If the visitor enters “ECMAScript”, then output “Right!”, otherwise – output: “You don’t know? ECMAScript!”*/
// let codeTheNameOfJavascript = prompt(`What is the “official” name of JavaScript?`,'');
// if(codeTheNameOfJavascript === "ECMAScript") {
// console.log(`Right! It's ECMAScript`);
// } else {
// console.log(`You don't know? “ECMAScript”!`);
// } //=> Good, you do it correctly

//Code above commented because to prevent annoying prompt popup ( I just don't like it ! );

//TASK 3:
console.log(` TASK 3: Show the sign:`);
/*
Using if..else, write the code which gets a number via prompt and then shows in alert:
1, if the value is greater than zero,
-1, if less than zero,
0, if equals zero.
In this task we assume that the input is always a number. */
/*
let numberShowtheSign = prompt(`Enter the number: `, '');
if(numberShowtheSign > 0) {
console.log(`1, if the value is greater than zero`);
} else if (numberShowtheSign < 0) {
console.log(`-1, if less than zero`);
} else if (numberShowtheSign === 0) {
console.log(`0, if equals zero.`);
} else {
console.log(`This is not a number anymore or a NaN`);
}
*/
//Yay, you do it right. I are not just make it readble
//but also create possibilty that can happen if user enter wrong too

//Code above commented because to prevent annoying prompt popup ( I just don't like it ! );

console.log(` TASK 4: Rewrite 'if' into '?'`);
//Simple, just rewrite if into ? operator

//Ans:
let resultConvertIftoQuestionMark = (adc + iwn < 4) ? 'Below' : 'Over';
//Just this fucking simple line but I just make it complicated
//50 point

console.log(` TASK 5: Rewrite 'if..else' into '?':`);
/*
Rewrite if..else using multiple ternary operators '?'.
For readability, it’s recommended to split the code into multiple lines.
*/
//Ans:
let messageRewriteElseIf =
(loginRewrite == 'Employee') ? 'Hello':
(loginRewrite == 'Director') ? 'Greetings':
(loginRewrite == '') ? 'No login' : '';
//Correct

0 comments on commit 90cabac

Please sign in to comment.