portátiles baratos

test

body {
display: flex;
flex-direction: row;
height: 100vh;
margin: 0;
}

#console {
flex: 1;
height: 100%;
background-color: black;
color: white;
font-family: monospace;
overflow-y: scroll;
}

#iframe {
flex: 2;
height: 100%;
border: none;
}

<iframe id="iframe" srcdoc="” sandbox=”allow-scripts”>

// Get the iframe window
const iframe = document.getElementById(‘iframe’);
const iframeWindow = iframe.contentWindow;

// Set up the console
const consoleDiv = $(‘#console’);
const consoleLog = function(text) {
consoleDiv.append(`

${text}

`);
consoleDiv.scrollTop(consoleDiv.prop(‘scrollHeight’));
};

// Define the exercise
const exercise = function() {
consoleLog(‘Create a variable called myNumber and set it to 5.’);
let myNumber;
try {
myNumber = 5;
if (myNumber === 5) {
consoleLog(‘Success! myNumber is 5.’);
} else {
consoleLog(‘Error: myNumber is not 5.’);
}
} catch (e) {
consoleLog(`Error: ${e.message}`);
}

consoleLog(‘Create a variable called myString and set it to “Hello, world!”.’);
let myString;
try {
myString = ‘Hello, world!’;
if (myString === ‘Hello, world!’) {
consoleLog(‘Success! myString is “Hello, world!”.’);
} else {
consoleLog(‘Error: myString is not “Hello, world!”.’);
}
} catch (e) {
consoleLog(`Error: ${e.message}`);
}

consoleLog(‘Create a variable called myBoolean and set it to true.’);
let myBoolean;
try {
myBoolean = true;
if (myBoolean === true) {
consoleLog(‘Success! myBoolean is true.’);
} else {
consoleLog(‘Error: myBoolean is not true.’);
}
} catch (e) {
consoleLog(`Error: ${e.message}`);
}

consoleLog(‘Create a variable called myArray and set it to an array of 3 numbers: 1, 2, and 3.’);
let myArray;
try {
myArray = [1, 2, 3];
if (myArray.length === 3 && myArray[0] === 1 && myArray[1] === 2 && myArray[2] === 3) {
consoleLog(‘Success! myArray contains the correct values.’);
} else {
consoleLog(‘Error: myArray does not contain the correct values.’);
}
} catch (e) {
consoleLog(`Error: ${e.message}`);
}

consoleLog(‘Create a function called add that takes two numbers as parameters and returns their sum.’);
let add;
try {
add = function(num1, num2) { return num1 + num2;
};
const result = add(3, 4);
if (result === 7) {
consoleLog(‘Success! add(3, 4) returns 7.’);
} else {
consoleLog(‘Error: add(3, 4) does not return 7.’);
}
} catch (e) {
consoleLog(`Error: ${e.message}`);
}
};

// Execute the exercise in the iframe window
const executeExercise = function() {
const exerciseCode = `(${exercise.toString()})();`;
iframeWindow.eval(exerciseCode);
};

// Execute the exercise when the iframe is loaded
iframe.onload = executeExercise;

Entradas Relacionadas

Artículo añadido al carrito.
0 artículos - 0,00