/*     Here is an example of a conditional in JavaScript */ var numberOfParticipants = 5; var maxNumberOfParticipants = 10; if (numberOfParticipants...

90.2K

Verified Solution

Question

Programming

/*

    Here is an example of a conditional inJavaScript

*/

var numberOfParticipants = 5;

var maxNumberOfParticipants = 10;

if (numberOfParticipants < maxNumberOfParticipants)

{

    console.log(\"You can add anotherparticipant now\");

}

else

{

    console.log(\"Sorry, you have reached themax number of participants and cannot add another\");

}

/*

    Now it's your turn - create a simpleconditional like my example. You can setup variables like I did orjust use

    hard-coded numbers

*/








/*

    Here is an example of creating a list inJavaScript it is called an array. Here I am creating a list of myfavorite songs:

*/

var myFavoriteSongs = [\"Shake It Off by Taylor Swift\", \"12 Shotsby Vic Mensa\", \"LSD by A$AP Rocky\"];

/*

    Now it's your turn. Create an array ofthe colors in a rainbow (ROYGBIV)

*/









/*

    Here is an example of creating a forloop in JavaScript. There is no foreach in JavaScript so we have todo it slightly differently than

    in App Inventor. Notice how it countsfrom zero not one!

*/

for (var index = 0; index < myFavoriteSongs.length;index++)

{

    var favoriteSong =myFavoriteSongs[index];

    console.log((index + 1) + \") \" +favoriteSong + \"\n\");

}

/*

    Now it's your turn. print out the arrayof the colors in a rainbow using a for loop

*/








/*

    Here is an example of adding an eventlistener to my button. Notice how the inline-function has a

    single line of coded within the {}:console.log(\"I was clicked!\");

*/

var myButton = document.getElementById(\"myButton\");

myButton.addEventListener(\"click\", function () {console.log(\"Iwas clicked!\");} );

/*

    Now it's your turn to do something whenyour button is clicked. I've created the variable \"yourButton\" foryou already

*/

var yourButton = document.getElementById(\"yourButton\");


Answer & Explanation Solved by verified expert
3.8 Ratings (378 Votes)
Program1conditional statement to check if a person can vot or notvar ageLimit 18var currentAge 12if currentAge    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students