html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!-- Created by Prashanth Kumar -->
secondary color (orange, green or purple) or none of these.
I also want to handle the situation for both uppercase and lowercase letters in the color the user types in.
Hint: remember the || means 'or'
This is what I have done:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>var color = prompt("Enter a color", " ");
var primary = ["red", "blue", "yellow"];
var secondary = ["orange", "green", "purple"];
if (color = primary) {
console.log(`You picked a primary color: ${color}`);
}
else if (color = secondary) {
console.log(`You picked a secondary color: ${color}`);
}
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
/* Created by Prashanth Kumar */
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Created by Prashanth Kumar
/*
New to JavaScript and teaching myself
I am trying to prompt the user for a color, then have the console report if the user typed a primary color (red, blue, or yellow) or a secondary color (orange, green or purple) or none of these.
I also want to handle the situation for both uppercase and lowercase letters in the color the user types in.
Hint: remember the || means 'or'
The app won’t let me copy and paste on here
*/
var color=prompt("Enter a color :","red");
color=color.toLowerCase(); // this will make color lowercase
var primaryColors=[
"red","blue","yellow", // you can add more here
];
var secondaryColors=[
"orange","green","purple", // you can add more here
];
if(primaryColors.includes(color)){
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run