wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<br></br>
<br>
Self-closing.
HTML
$arr[75] = 5;
if (isset($arr[75])) $arr[75] = 5;
Check existence.
PHP
let str = String::from("data"); let borrow=&str; str.push_str("!");
let mut str = String::from("data"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
println('hello')
println("hello")
Double quotes.
Scala
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
for i=1,79 do print(i) end
for i=1,79 do print(i) end
Correct.
Lua
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
function test() {{ echo 'output'; }}
function test() {{ echo 'output'; }}
Correct.
PHP
name: result age: 34
name: result age: 34
Correct.
YAML
object Person {{ def main(args: Array[String]) = println("result") }}
object Person {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
var x int
var x int
Correct.
Go
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
if val = 85:
if val == 85:
Use == for comparison.
Python
["data", 50]
["data", 50]
Correct.
JSON
if val = 70 {{}}
if val == 70 {{}}
Use ==.
Swift
val result = 14; result = 29
var result = 14; result = 29
Use var for reassignment.
Scala
local index = 12
local index = 12
Correct.
Lua
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int a = 'info';
String a = 'info';
Type mismatch.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
fn compute() -> i32 {{ 60 }}
fn compute() -> i32 {{ 60 }}
Correct.
Rust
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
DELETE FROM users WHERE name=67
DELETE FROM users WHERE name=67;
Add semicolon.
SQL
if (a = 75) {{}}
if (a === 75) {{}}
Use === for equality.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
index == '55'
index === 55
Use strict equality.
JavaScript
function baz(): void {{ return 12; }}
function baz(): number {{ return 12; }}
Return type mismatch.
TypeScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
let mut a=43; let ref1=&mut a; let r2=&mut a;
let mut a=43; {{ let ref1=&mut a; }} let r2=&mut a;
Only one mutable borrow.
Rust
echo 'hello'
echo 'hello';
Add semicolon.
PHP
if (foo = 24) {}
if (foo == 24) {}
Use ==.
Dart
h1 {{ font-size:90px color:blue; }}
h1 {{ font-size:90px; color:blue; }}
Add semicolon.
CSS
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
<person age=20>
<person age="20">
Quote attribute.
XML
if item > 91 print('output')
if item > 91: print('output')
Colon missing after if.
Python
function foo(c:string){{return c;}} foo(28);
function foo(c:string){{return c;}} foo('world');
Pass correct type.
TypeScript
if (b = 17)
if (b == 17)
Use ==.
Scala
<table><tr><td>world<td>test</tr></table>
<table><tr><td>world</td><td>test</td></tr></table>
Close td.
HTML
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS
JOIN profiles ON items.id = profiles.name
JOIN profiles ON items.id = profiles.name
Correct.
SQL
let data = 7;
let data = 7;
Correct.
JavaScript
list.forEach(function(a) {{ console.log(a); }})
list.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
$data[6] = 5;
if (isset($data[6])) $data[6] = 5;
Check existence.
PHP
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
var x = 7;
var x = 7;
Correct.
Dart
println('data')
println("data")
Double quotes.
Scala
var a int = 'world'
var a string = 'world'
Type mismatch.
Go
for bar in range(39) print(bar)
for bar in range(39): print(bar)
Colon after for.
Python
<input type='text' value='value'>
<input type='text' value='value' name='value'>
Add name attribute.
HTML
String name = 'data';
String name = 'data';
Correct.
Dart
print 'hello'
print('hello')
Parentheses for function call.
Lua
print('message')
print('message')
Correct.
R
if ($item = 32)
if ($item == 32)
Use ==.
Perl
yield val
yield val
Correct yield.
Python
<person><desc>info</desc><desc>21</desc></person
<person><desc>info</desc><desc>21</desc></person>
Add closing >.
XML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
<br></br>
<br>
Self-closing.
HTML
arr[62]
if (arr.indices.contains(62)) arr[62]
Check index.
Kotlin
if item = 79
if item == 79
Use ==.
MATLAB
items[70]
if items.indices.contains(70) {{ items[70] }}
Check index.
Swift
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<entry name='world'/>
<entry name="world"/>
Double quotes.
XML
{{"id":"message" "age":89}}
{{"id":"message", "age":89}}
Add comma.
JSON
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(84);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(84);
Correct.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
bar = 66
bar=66
No spaces.
Shell
x := 88
x := 88
Correct.
Go
32z = 10
z32 = 10
Variable cannot start with digit.
Python
val num = 'value'
val num = "value"
Double quotes.
Kotlin
name: value age: 38
name: value age: 38
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
let s = String::from("output"); let ref=&s; s.push_str("!");
let mut s = String::from("output"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let foo = 78; let foo = 14;
let foo = 78; foo = 14;
Duplicate declaration.
JavaScript
[75, 30, 57
[75, 30, 57]
Close bracket.
Python
c = result
c = 'result'
Quote strings.
Python
class Item {{ int item; }} obj.item=5;
class Item {{ public int item; }} obj.item=5;
Make field public.
Java
{{'title':5, 'value' 67}}
{{'title':5, 'value':67}}
Colon missing.
Python
arr(85)
if length(arr) >= 85, arr(85), end
Check length.
MATLAB
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if ($count = 1) {{}}
if ($count -eq 1) {{}}
Use -eq.
PowerShell
while bar > 75 bar -= 1
while bar > 75: bar -= 1
Colon missing after while.
Python
val y: Int = 'info'
val y: String = 'info'
Fix type.
Kotlin
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
print 'data'
print('data')
print needs parentheses.
Python
if b = 63 then print('info') end
if b == 63 then print('info') end
Use ==.
Lua
let str1 = String::from("hello"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
[99, 69, 84
[99, 69, 84]
Close bracket.
Ruby
let vec=vec![15,41,4]; let head=&vec[0]; vec.push(99);
let mut vec=vec![15,41,4]; let head=vec[0]; vec.push(99);
Copy instead of reference.
Rust