My first suggestion is to use true/false boolean instead of checking the strings "yes" and "no" to help simplify your code. I've made a funciton to help convert this for you. It also handles what happens if someone type "NO" or "yEs" for example.
Also, just using consistent formatting helps make the code easier to read.
function promptToBoolean(txt) {
return /yes/i.test(prompt(txt));
}
var javascript = promptToBoolean("Want to learn javascript? (Type yes or no)");
var docker = promptToBoolean("Want to learn docker? (Type yes or no)");
var time = promptToBoolean("do you have time ? (type yes or no)");
if (!time) {
alert("Nobody is busy its just a matter of PRIORITIES");
}
if (javascript && time && docker) {
alert("keep patience first learn docker and then learn javascript");
} else if (javascript && docker && !time) {
alert("so what should I do if u don't have time ?");
} else if (javascript && time) {
alert("go and learn javascript");
} else if (!time && javascript) {
alert("\"A smarter way to learn javascript\" will solve your problem in less time ");
} else if (docker && time) {
alert('go n learn docker');
} else if (!time && docker) {
alert("\"Docker Deep Dive\" will solve your problem in less time ");
} else {
alert('You are not from us');
}
Another way to help manage them is to better follow the logic, don't repeat yourself, and don't use unnecessary parenthesis or nested statements.
For example, this
if ((javascript ==="yes" && time === "yes") && (docker === 'yes' && time ==='yes') ) {
can be re-written as just
if (javascript && time && docker) {
And then this:
} else if (javascript === "yes" && docker === "yes") {
if (time === "no") {
alert("so what should I do if u don't have time ?");
}
}
can be re-written as:
} else if (javascript && docker && !time) {
alert("so what should I do if u don't have time ?");
}
I also recommend sectioning things off into large chunks to manage the logic, for example with time, that seemed to be checked quite often, so you could just do that check once and then manage your other logic inside those blocks of code
if (time) {
//Put everything in here where time is true
} else {
//Put everything in here where time is false
}
Like this:
function promptToBoolean(txt) {
return /yes/i.test(prompt(txt));
}
var javascript = promptToBoolean("Want to learn javascript? (Type yes or no)");
var docker = promptToBoolean("Want to learn docker? (Type yes or no)");
var time = promptToBoolean("do you have time ? (type yes or no)");
if (time) {
if (javascript && docker) {
alert("keep patience first learn docker and then learn javascript");
} else if (javascript) {
alert("go and learn javascript");
} else if (docker) {
alert('go n learn docker');
}
} else {
alert("Nobody is busy its just a matter of PRIORITIES");
if (javascript && docker) {
alert("so what should I do if u don't have time ?");
} else if (javascript) {
alert("\"A smarter way to learn javascript\" will solve your problem in less time ");
} else if (docker) {
alert("\"Docker Deep Dive\" will solve your problem in less time ");
} else {
alert('You are not from us');
}
}