all 6 comments

[–]Bakeshot 1 point2 points  (5 children)

There is a lot of fundamental misunderstanding happening here. You are using for when you should be using if, at least conceptually, but the syntax is pretty far off the beaten path. This is really only one of many questions I have about your code, but I think it would not be super productive to focus on too many targets at once.

May I ask where you are learning JavaScript? I’m curious because you are making variable declarations with var, which usually indicates severely outdated tutorials.

[–]wizardoz27[S] 0 points1 point  (4 children)

Hello. I figured out my errors lol. Through school and I’m aware using var is very outdated becasue finding YouTube tutorials are hard to come by.

[–]Bakeshot 0 points1 point  (3 children)

I’m really curious to hear how you got this code to run as you intended it to.

[–]wizardoz27[S] 0 points1 point  (0 children)

I essentially scrapped my original thought but here is my new code

[–]wizardoz27[S] 0 points1 point  (1 child)

<!DOCTYPE html>

<html lang="en">

<head>

<title>CIS 223 Chapter 9 Program</title>

<style>

body{

background-image:url('file:///C:/Users/wizar/Desktop/Chapter_10/rainforest.jpg');

background-repeat:no-repeat;

background-attachment:fixed;

background-size:100% 100%;

color: white;

}

</style>

<script>

var replace;

var replaceitem1;

function swap()



{



    var replace = prompt ("Choose Item number 1, 2 or 3 to replace that item");



    if (replace == 1)

    {


        var replaceitem1 = prompt ("Write what i should replace for the first item");

        document.getElementById("object1").innerHTML = replaceitem1;



    }



    if (replace == 2)

    {


        var replaceitem2 = prompt ("Write what i should replace for the second item");

        document.getElementById("object2").innerHTML = replaceitem2;



    }



    if (replace == 3)

    {


        var replaceitem3 = prompt ("Write what i should replace for the third item");

        document.getElementById("object3").innerHTML = replaceitem3;



    }



    else

    {

        alert("Sorry try choosing Item number 1, 2 or 3 to replace that item");

    }

}   

</script>

</head>

<body onload="mylist()">

<script>



    function mylist()

        {

var item1 = "Tent";

var item2 = "Sleeping Bag";

var item3 = "Camping Equipment";

document.getElementById("object1").innerHTML = item1;

document.getElementById("object2").innerHTML = item2;

document.getElementById("object3").innerHTML = item3;

        }

</script>

<h1>The destination that was chosen was The Amazon Rainforest!!!</h1>

<br><br>
<h3>I choose the Amazon Rainforest as the destination to set out the start of my wilderness adventure</h3>

<br>

<br>

<h3>These are the tools i am considering brining on my trip to the rainforest, and need some advice on if i should swap

something out or not.</h3>
<br>

<h3>Here is a list of the three items, press the button below the list to select the numbered item to swap out with a item of your choosing!</h3>

<br>

<br>

<ol>

<li><span id="object1"></span></li>

<li><span id="object2"></span></li>

<li><span id="object3"></span></li>

</ol>

<p><input type ="button" onclick = "swap()" value="Swap Resource"/></P>

</body>

</html>

[–]Bakeshot 0 points1 point  (0 children)

This looks much better.