Question

Please help me with this code for javascript. <!DOCTYPE html> <html> <head> <title>Strings and Arrays</title> <script>...

Please help me with this code for javascript.

<!DOCTYPE html>

<html>

<head>

<title>Strings and Arrays</title>

<script>

function wrangleArray() {

var string1 = prompt("Enter: This class is going to fast");//Must be entered by the user

var string1 = "";//Is this right? I want that string to change later by a series of prompt questions

document.getElementById("div1").innerHTML = "<p>" + sentence + "</p>";

var words = sentence.split(" ");//I need to convert my string to an Array is this the way to do it?

var words = prompt("Choose which words to replace: This class is going to fast");//I want the user to enter any of the words from the string

var words1 = prompt("Replace with these words.");//I want the user to enter new words to replace my original striing

/*Here is where I am having problems making this work. I don't know if what i want to do is possible in JS without creating too long of code

I wanted to make a simple codes that too my prompt string and gave the user options to change the sentence around with arrays, replace() and the final outcome of the sentence should be toUpperCase().

*/

var message = words.splice(3,4,"fun");//From. this point the code does not comply.

alert('Removed words: ' + message);

document.getElementById("div2").innerHTML = "<p>" + words.join(" ") + "</p>";

}

</script>

</head>

<body>

<div id="div1"></div>

<div id="div2"></div>

<script>wrangleArray();</script>

</body>

</html>

thank you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <array>
#include <cstddef>
using namespace std;
//display map. initialize to nullptrs
//reserve
//list reserved seats
//quit

//Error check section + row;
int ROWS = 10;
int COLS = 20;
int displaySeat(char seatingChart[][20], int rows);
int chooseSeat (char seatingChart[][20], int rows);
int alreadyTaken (char seatingChart[][20],int rows);
void showMenu();
int giveUpSeat (char* seatingChart[][20],int rows,char* name[20]);
int errorMessage (int option, char sectionLetter);

int main()
{
int option;
cin >> option;
showMenu();
cout << "Welcome to SMU's amphitheater!" << endl;
char sectionA[10][20];
char sectionB[10][20];
char sectionC[10][20];
char sectionLetter;
while(option != 4){
if (option == 1){
displaySeat(sectionA,10);
displaySeat(sectionB,10);
displaySeat(sectionC,10);
} else
if (option == 2){
cout << "Enter section letter:";
cin >> sectionLetter;
if (sectionLetter = 'a') {chooseSeat(sectionA,10);
}else if(sectionLetter = 'b') {chooseSeat(sectionB,10);
}else if(sectionLetter = 'c') {chooseSeat(sectionC,10);
}else {errorMessage(999,'z');}
} else
if (option == 3){
cout << alreadyTaken(sectionA,10);
cout << alreadyTaken(sectionB,10);
cout << alreadyTaken(sectionC,10);
}
}
return 0;
}
/*
Display a chart for A section with x and o's to show
available seats
*/
int displaySeat(char seatingChart[][20]){
//const char seats[ROWS][COLS];
cout << "Seating Chart : " << endl << endl;
cout << " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20";
cout << "1" <<endl <<"2" <<endl<<"3"<<endl<<"4"<<endl<<"5"<<endl<<"6"<<endl<<"7"<<endl<<"8"<<endl<<"9"<<endl<<"10"<<endl;
for (int i=0; i< ROWS; i++){
for (int j=0; j<20;j++){
cout << seatingChart[i][j];
}
}
}

/*
Reserving a seat, type in Section, Row, and column.
If row && seat && section choice is taken, cout it is taken
conditions : seating is = nullptr || = available;
else it is taken.
*/
int chooseSeat (char seatingChart[][20], int rows){
bool taken = true;
for (int i=0; i< rows; i++){
for (int j=0; j<20;j++){
if (*seatingChart[][20] == nullptr && *seatingChart[][20] != taken )
{
*seatingChart[i][j] = taken;
cout << "This seat is already taken" << endl;
} else {
*seatingChart[i][j] = available;
int chosenRow;
int chosenCol;
string name;
*seatingChart = new char[chosenRow][chosenCol];
//row #
cout << "Enter row number : " << endl;
cin >> chosenRow;
  
//col #
cout << "Enter column number : " << endl;
cin >> chosenCol;
  
cout << "Enter your name : " << endl;
cin>> name;
  
cout << name << "have reserved" << seatingChart[chosenRow][chosenCol] << endl;
}
}
}
}
int alreadyTaken (char seatingChart[][20],int rows){
//It is taken if it is not null or if there is a name
// in the element (if taken) display 'x' else display 'o'
*seatingChart = new char[rows];
for (int i=0; i< rows; i++){
for (int j=0; j<20;j++){
if (*seatingChart[][20] != nullptr && *seatingChart[][20] != name ){
*seatingChart[i][j] = available;
} else {
*seatingChart[i][j] = taken;
}
}
}
}

void showMenu (){
cout << "Menu: " <<endl << endl;
cout << "1.Display the theatre seating chart." <<endl;
cout << "2.Reserve a seat" <<endl;
cout << "3.List of reserved seats by section" <<endl;
cout << "4.Quit" << endl;
}
int giveUpSeat (char* seatingChart[][20],int rows,char* name[20]){
//if it has a name, remove the name and replace with nullptr.
if (*seatingChart == name){
*seatingChart = nullptr;
} else {
*seatingChart = available;
}
}

int errorMessage (int option, char sectionLetter){
if (option != 1 && option != 2 && option != 3 && option != 4 && sectionLetter!='a' && sectionLetter!='b' && sectionLetter !='c'){
cout << "Oops! This is not one of the options." << endl;
}
}

Add a comment
Know the answer?
Add Answer to:
Please help me with this code for javascript. <!DOCTYPE html> <html> <head> <title>Strings and Arrays</title> <script>...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is my code so far: <!DOCTYPE html> <html> <head> <title>JavaScript is fun</title> <meta charset="utf-8" />...

    This is my code so far: <!DOCTYPE html> <html> <head> <title>JavaScript is fun</title> <meta charset="utf-8" /> </head> <body> <script type ="text/javascript"> //declare a variable and store text in it var x = "JavaScript is fun"; //write the variable 5 times document.write(x + x + x + x + x); //store 5 as string in variable x x = "5"; //store 3 as string in variable y var y = "3"; //write the value x + y to the document document.write("<br>");...

  • <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 4 Hands-on Project 4-3 Author: Da...

    <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 4 Hands-on Project 4-3 Author: Date:    Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Hands-on Project 4-3</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.05819.js"></script> </head> <body> <header> <h1> Hands-on Project 4-3 </h1> </header> <article> <div id="results"> <p id="resultsExpl"></p> <ul> <li id="item1"></li> <li id="item2"></li> <li id="item3"></li> <li id="item4"></li> <li id="item5"></li> </ul> </div> <form> <fieldset> <label for="placeBox" id="placeLabel"> Type the name of a place, then click Submit: </label> <input type="text" id="placeBox"...

  • <html>     <head>       <title>Sign Up page</title>   <form name="validationForm" method="post" onsubmit="return checkvalidation()">      &n

    <html>     <head>       <title>Sign Up page</title>   <form name="validationForm" method="post" onsubmit="return checkvalidation()">         <!--div class-->       <div class="formvalidation">       <label>Your first Name</label>        <span id="showname"></span>        <!--label for firstname-->       <input type="text" name="firstname" class="formsignup"  id ="firstn" placeholder="Enter your Name">      <br><br>           <!--lastname-->       <label>Your last Name</label> <span id="showlname"></span>       <input type="text" name="lastname" class="formsignup" id="lastn" placeholder="Enter your last Name">       <br><br>        <!--email-->         <label>Your Email</label>          <span id="showemail"></span>         <input type="email" name="emailid" class="formsignup" size="45" id="emailn" placeholder="Enter your Email">        <br><br> <input type="submit" value="send">     </div>           </form> <script>      function checkvalidation(){     var name = document.forms["validationForm"]["firstname"].value;     var lname...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • in the following java script code follow the instructions provided <!DOCTYPE html> <html> <head> <!-- JavaScript...

    in the following java script code follow the instructions provided <!DOCTYPE html> <html> <head> <!-- JavaScript 6th Edition Chapter 5 Hands-on Project 5-2 Author: Date:    Filename: index.htm --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Hands-on Project 5-2</title> <link rel="stylesheet" href="styles.css" /> <script src="modernizr.custom.05819.js"></script> </head> <body> <header> <h1> Hands-on Project 5-2 </h1> </header> <article> <h2>Change of address form</h2> <form> <fieldset id="contactinfo"> <label for="addrinput"> Street Address </label> <input type="text" id="addrinput" name="Address" /> <label for="cityinput"> City </label> <input type="text" id="cityinput" name="City"...

  • This question relates to Javascript. Could you please show me why my code is not working?...

    This question relates to Javascript. Could you please show me why my code is not working? I want to create 2 text boxes and have the user enter something into both of them. If the text entered into both boxes is identical the a green message is made visible. If the boxes are different a red message is made visable. Please keep it simple because I am new to javascript. <html> <head>               <title></title>        <script>...

  • Could you please help me write a Javascript code that will show a smiley face picture...

    Could you please help me write a Javascript code that will show a smiley face picture when I click the button. The picture should not display until the button is pressed. Here is my attempt at the code. It does not work. Please keep the code as simple as you can as I am new to coding. Please also use the <div> tag if possible, onclick and use the getElementById. Thank you <html> <body> <img id="exampleImage" src="smileyFace.png" /> <button onclick="pushButton()">Try...

  • JavaScript (Please debug this code) When a user enters a string in the input box, the...

    JavaScript (Please debug this code) When a user enters a string in the input box, the program is designed to add the string to an array. When the array reaches a certain length, the program displays all the users' entries in a list on the page. When you finish debugging, the user's entry in the input box should be cleared each time the submit button is clicked. Additionally, after five strings are submitted, the entire list of submitted strings should...

  • <!DOCTYPE HTML> <html lang="en">    <title>JavaScript Array Lab</title>    <script src="script.js"></script>    <body>        <p>To...

    <!DOCTYPE HTML> <html lang="en">    <title>JavaScript Array Lab</title>    <script src="script.js"></script>    <body>        <p>To test your function, call divideArray() from the JavaScript console in the browser.</p>    </body> </html> Don't edit your code on the above code and do not copy from others', plz! // Put your solution here in script.js Write the function divideArray() in script.js that has a single numbers parameter containing an array of integers. The function should divide numbers into two arrays, evenNums for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT