There are several issues here:
First, you are redefining the computer and bitrate variables after prompting the user for input. This will prevent the prompt from appearing on the screen. Instead, you should only declare these variables once and assign them the values returned by prompt().
let computer = prompt("What kind of computer do you have (Windows or Mac)?");
let bitrate = prompt("What bitrate does it have (32Bit or 64Bit)?");
Second, in your if condition, you should check both computer and bitrate values separately using logical operators (&&). This ensures that both conditions are met before executing the alert or you can make different control for user input. But user can write anything HTML radio input will be more accurete.
if (computer === "Windows" && "32Bit") {
alert ("Check out Ubuntu Linux or Linux Mint Faye for your "( + computer + )"! It feels just like windows and it has got only little mb!");
}
Lastly, using parentheses around the + operator in your alert message, these parentheses are not necessary, using them cause a syntax error.
For more information on JavaScript syntax and conditionals, you can refer to the
If Statement
Prompt
Radio input
InnerHTML
Dom manupulation
Actually, all of that quite well explained in this curriculum. However, using prompt is not recommended for taking input from users in modern web applications. It’s better to use other input methods or form elements for a better user experience.
Here’s a working sample of your code. However, keep in mind that if the user enters “windows 11” or “x86”, it will not work as expected. You may need to implement additional checks, possibly using regular expressions, to handle various inputs more robustly.
let computer = prompt("What kind of computer do you have (Windows or Mac)?");
let bitrate = prompt("What bitrate does it have (32Bit or 64Bit)?");
if (computer === "Windows" && bitrate === "32Bit") {
alert("Check out Ubuntu Linux or Linux Mint for your " + computer + "! It feels just like Windows and uses minimal resources.");
} else if (computer === "Windows" && bitrate === "64Bit") {
alert("Do you consider your " + computer + " to newer macOS?");
} else if (computer === "Mac" && bitrate === "32Bit") {
alert("Upgrade to a newer version of macOS for improved performance and security.");
} else if (computer === "Mac" && bitrate === "64Bit") {
alert("Your " + computer + " is capable of running the latest macOS version smoothly.");
} else {
alert("Invalid input. Please provide valid answers.");
}