私は小さな仕事をして、仕事の仕組みを理解しています... "Create New Startup"ボタンは、配列 'startupX'からの入力と、 'スタートアップY'。私は生成された文字列全体を保存するための "Favorite Startup"ボタンをどのようにして、最終的には "お気に入り印刷"ボタンでお気に入りの文字列をすべて印刷するかを理解しようとしています。何とかstr.split()で文字列を配列として保存できますか? ボタンで生成された文章を保存する
var startupX = ['Uber', 'Google', 'Amazon', 'Apple', 'Facebook', 'Twitter'];
var startupY = ['Slack', 'Trello', 'Tesla', 'Hyperloop', 'Harvest'];
function chooseStartup() {
var x = startupX[Math.floor(Math.random()*startupX.length)];
var y = startupY[Math.floor(Math.random()*startupY.length)];
document.getElementById('startupX').innerHTML = x;
document.getElementById('startupY').innerHTML = y;
};
<body>
<h1 id="xForY"></h1>
<h1 id="sentence">A startup that is
<span id="startupX"></span>, but for
<span id="startupY"></span>
</h1>
<div id="inputs">
<button onclick="chooseStartup()" id="create">Create New Startup</button>
<button id="save">Favorite Startup</button>
<button id="print">Print Favorites</button>
</div>
<h2 id="favorites">
</h2>
<script src='http://code.jquery.com/jquery-latest.min.js'></script>
<script src='js/madlib-console.js'></script>
</body>
。次に、chooseStartup()関数の実行中に、3番目の変数を生成された文に設定します。 – mwilson